Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp?
I've heard it said, by no less a guru than Peter Norvig, that Python is a lot like Lisp without the parentheses at least for the basics of Python. For pedagogical reasons, I'm wondering if it would be easy to implement a big subset of Python in Scheme. The basics of Scheme or Lisp are amazingly easy to implement. Would implementing a subset of Python in a Scheme subset be a clever way to easily implement a lot of Python? (This isn't for practical reasonsI'm just curious.) Chris -- https://mail.python.org/mailman/listinfo/python-list
Re: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp?
Exceptions, modules, OOP, etc. would be tricky to implement in Scheme but at least the basics like for loops, while loops, assignment etc. would seem doable and very instructive for students.they would thereafter, for all time, have a mental image of what the Python interpreter is doing. > But then theres also (apart from parsing) all kinds of semantic differences > eg: > > - exceptions > > - modules > > - OOP milarky > > - C interfacing in Baskin Robbins number of flavours > > - carefully crafted portable veneer on top of intrinsically non portable OSes > > -- https://mail.python.org/mailman/listinfo/python-list
Re: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp?
On Friday, January 3, 2014 11:10:07 AM UTC-6, Devin Jeanpierre wrote: > A lecturer of mine back in university did this (implemented a subset > > of Python in Racket). My understanding is that this is primarily > > interesting to show that Racket is not as crazily different as it > > looks from the syntax. Is that on the web anywhere? That would be very interesting to look at. I'm sure others would find it useful too. -- https://mail.python.org/mailman/listinfo/python-list
Re: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp?
Thanks.. I think your 10% Python idea is the way to go. And you are right that most of Python is not needed in an intro course. -- https://mail.python.org/mailman/listinfo/python-list
Instead of deciding between Python or Lisp for a programming intro course...What about an intro course that uses *BOTH*? Good idea?
Instead of learning only Scheme or only Python for a one semester intro course, what about learning BOTH? Maybe that could somehow get the benefits of both? I'm thinking that for the VERY beginning, Scheme is the fastest language to get beginners up and running writing code due to the extremely minimal simple syntax. I'm thinking half way into the semester, instead of moving into intermediate Scheme, perhaps that is a good time to switch to Python? Would a little strong intro to 2 nice languages in one semester be same/good/worse/better than just 1? cs -- https://mail.python.org/mailman/listinfo/python-list
re.sub question (regular expressions)
What does this line do?... input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_) Does it remove parentheses from words? e.g. (foo) -> foo ??? I'd like to replace [a-zA-Z] with \w but \w makes it blow up. In other words, re.sub("(\w+)", '"\\1"', input_) blows up. Why? cs -- http://mail.python.org/mailman/listinfo/python-list
Re: re.sub question (regular expressions)
On Oct 16, 9:51 am, MRAB wrote: > What do you mean "blow up"? It worked for me in Python v2.6.2. My bad. False alarm. This was one of those cases where a bug in another area appears like a bug in a different area. Thank for the help. cs -- http://mail.python.org/mailman/listinfo/python-list
How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?
How do subprocess.Popen("ls | grep foo", shell=True) with shell=False? Does complex commands with "|" in them mandate shell=True? cs -- http://mail.python.org/mailman/listinfo/python-list
Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?
On Jun 10, 6:52 am, Nobody wrote: > Without the p1.stdout.close(), if the reader (grep) terminates before > consuming all of its input, the writer (ls) won't terminate so long as > Python retains the descriptor corresponding to p1.stdout. In this > situation, the p1.wait() will deadlock. > > The communicate() method wait()s for the process to terminate. Other > processes need to be wait()ed on explicitly, otherwise you end up with > "zombies" (labelled "" in the output from "ps"). You are obviously very wise on such things. I'm curious if this deadlock issue is a rare event since I'm grep (hopefully) would rarely terminate before consuming all its input. Even if zombies are created, they will eventually get dealt with my OS w/o any user intervention needed right? I'm just trying to verify the naive solution of not worrying about these deadlock will still be ok and handled adequately by os. :) cs -- http://mail.python.org/mailman/listinfo/python-list
newbie subprocess.Popen performance issues/questions
I tried to use subprocess.Popen to make my web app do a bunch of stuff in separate processes today. It appeared like only the first one finished and/or the rest of the forked processes crashed. I only have around 300Mb. Is it possible that my subprocess.Popen code was swapping to disk so much that most of the Popen processes just crashed? Are there any tools to monitor how much memory I should upgrade to and/ or what else would cause a subprocess.Popen symphony have problems? Sincerely, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie subprocess.Popen performance issues/questions
On Jun 15, 2:44 am, News123 wrote: > ChrisSeberinowrote: > > I tried to use subprocess.Popen to make my web app do a bunch of stuff > > in separate processes today. It appeared like only the first one > > finished and/or the rest of the forked processes crashed. > First thing to do would be to show us a little code and to look for the > exit codes of your subprocess calls. OK I've appended the 236 line Python script below that gets invoked with Popen asynchronously. In summary what it does is set up a web site with a hosting provider. That involves using modules (Mechanize and Selenium) that literally launch browsers and simulate mouse and keyboard actions to get the job done. Furthermore, Expect scripts are launched that copy code and SSH to remote accounts to do other work. Is any of that I just mentioned especially troublesome in a Popen process? # hosting company set up script import sys import os sys.path.append(os.path.dirname(__file__) + "/../selenium") import selenium import mechanize import subprocess import smtplib import re HOSTMONSTER_URL = "https://www.hostmonster.com"; SELENIUM_PORT = SUCCESS_DOMAIN = "Successfully assigned _DOMAIN_ as addon domain" SUCCESS_DB = 'Added the database \w +_DB_http://"; + domain) browser.start() # Set the WordPress instance title and admin email address. browser.open("/wp-admin/install.php") browser.type("weblog_title", title) browser.type("admin_email", wp_admin_email) browser.click("Submit") browser.wait_for_page_to_load(TIMEOUT) # Perform authentication for the Selenium browser. (WordPress instance) temp_password = browser.get_html_source() beg = temp_password.find("") beg = temp_password.find("", beg + 1) + len("") end = temp_password.find("", beg) temp_password = temp_password[beg:end] browser.click("link=Log In") browser.wait_for_page_to_load(TIMEOUT) browser.type("user_login", "admin") browser.type("user_pass", temp_password) browser.click("wp-submit") browser.wait_for_page_to_load(TIMEOUT) # Change the admin password. browser.open("/wp-admin/profile.php#password") browser.type("pass1", wp_admin_password) browser.type("pass2", wp_admin_password) browser.click("submit") browser.wait_for_page_to_load(TIMEOUT) # Delete the default WordPress instance post. browser.click("link=Posts") browser.wait_for_page_to_load(TIMEOUT) browser.click("link=Hello world!") browser.wait_for_page_to_load(TIMEOUT) browser.click("link=Move to Trash") browser.wait_for_page_to_load(TIMEOUT) # Add a WordPress instance post. #browser.click("//d...@id = 'wpbody-content']/div[2]/h2/a") #browser.wait_for_page_to_load(TIMEOUT) #browser.type("title", post_title) #browser.click("publish") #browser.wait_for_page_to_load(TIMEOUT) # Activate all the WordPress instance plugins. browser.open("/wp-admin/plugins.php") browser.wait_for_page_to_load(TIMEOUT) browser.click("//inp...@type = 'checkbox']") browser.select("action", "label=Activate") browser.click("doaction_active") browser.wait_for_page_to_load(TIMEOUT) # Configure the WordPress instance All In One SEO Pack plugin. browser.click("link=Settings") browser.wait_for_page_to_load(TIMEOUT) browser.click("link=All in One SEO") browser.wait_for_page_to_load(TIMEOUT) browser.click("aiosp_enabled") browser.type("aiosp_home_title", title) browser.type("aiosp_home_description", description) browser.type("aiosp_home_keywords", keywords) browser.click("Submit") browser.wait_for_page_to_load(TIMEOUT) # Configure the WordPress instance Akismet plugin. browser.click("link=enter your WordPress.com API key") browser.wait_for_page_to_load(TIMEOUT) browser.type("key", wp_akismet_key) browser.click("akismet_discard_month") browser.click("submit") browser.wait_for_page_to_load(TIMEOUT) # Configure the WordPress instance All In One Adsense And YPN! plugin. browser.click("link=Adsense") browser.wait_for_page_to_load(TIMEOUT) browser.type("ai_client", wp_adsense_id) browser.click("action") # Generate the WordPress instance initial Google sitemap. browser.click("link=XML-Sitemap") browser.wait_for_page_to_load(TIMEOUT) browser.click("link=Click here") browser.wait_for_page_to_load(TIMEOUT) # Set the WordPress instance theme. browser.click("link=Appearance") browser.wait_for_page_to_load(TIMEOUT) browser.click("link=Activate") browser.wait_for_page_to_load(TIMEOUT) # Close the Selenium browser. (WordPress instance) browser.stop() # Will need to improve thislog a report. if True: output += domain + " WordPress configuration: SUCCESS" + "\n" else: output += domain + " WordPress configuration: FAIL" + "\n" open(auto_log, "a").write(output.split("\n")[-2]) # Email the results to the user. email_handle = smtplib.SMTP("localhost") email= "Subject: " + domain + " report\n" + output email_handle.sendmail("supp...@seoconquer.com", wp_admin_email, email) -- http://mail.python.org/mailman/listinfo/python-list
Possible to make subprocess.Popen jobs run serially rather than in parallel?
Possible to make subprocess.Popen jobs run serially rather than in parallel? In other words, if a computer is low on memory and doesn't mind waiting.can Popen be configured to submit to a queue and run jobs *ONE AT TIME*?? That might be useful and avoid crashes and disk swapping. cs -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible to make subprocess.Popen jobs run serially rather than in parallel?
On Jun 15, 2:03 pm, Stephen Hansen wrote: > Just call "process.wait()" after you call process = subprocess.Popen(...) I may have not been clear. I *don't* want web app to block on Popen.wait. I *do* want the Popen process to run in the background which web app still runs doing other things. Rather, I don't want *MANY* Popen processes to run in the backgroundjust one preferably. cs -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible to make subprocess.Popen jobs run serially rather than in parallel?
On Jun 16, 11:27 am, Stephen Hansen wrote: > On 6/16/10 7:04 AM, Chris Seberino wrote: > > > On Jun 15, 2:03 pm, Stephen Hansen wrote: > > >> Just call "process.wait()" after you call process = subprocess.Popen(...) > > > I may have not been clear. > > I *don't* want web app to block on Popen.wait. > > I *do* want the Popen process to run in the background which web app > > still runs doing other things. > > > Rather, I don't want *MANY* Popen processes to run in the > > backgroundjust one preferably. > > The simpliest method that comes to mind then is to have a "Process > Runner" thread that you start when the web app begins. Then create a > Queue.Queue() instance, share it between said thread and your web app. > > When you want to run an application, do Queue.put( (argspec,) ) > > Have Process Runner do a blocking wait with Queue.get(). > > When you wake it up with Queue.put, have it pass the args off into > subprocess.Popen. Then have it do process.wait() to block on said > process's completion. > > Once it's done, our little infinite loop jumps to the top, and it calls > queue.get() again -- if another process request has been put in, it > immediately gets it and goes and runs it, thus your processes are > executing one at a time. If nothing is ready for it, it blocks until you > wake it up. > > Something like (written off of top of head, may have errors): > > import threading > import Queue > import subprocess > > class ProcessRunner(threading.Thread): > def __init__(self, queue): > self._queue = queue > self.setDaemon(True) > > def run(self): > while True: > args, kwargs = self._queue.get() > process = subprocess.Popen(*args, **kwargs) > process.wait() > > # ... And somewhere in our real web-app initialization, we do... > > runner_queue = Queue.Queue() > runner_thread = ProcessRunner(runner_queue) > runner_thread.start() > > # ... And later, when we want to start a process ... > > runner_queue.put( (("ls -la",), {"shell": False}) ) # (*) see bottom > > -- > > Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog:http://meh.ixokai.io/ > > P.S. Passing in 'args' and 'kwargs' into the queue is usually in my > experience overkill (in addition to being slightly ugly); generally the > subprocesses I want to run are similar in nature or environment, so I > just have the runner-thread smart. But, the above is the most naive > implementation. > > signature.asc > < 1KViewDownload Thanks all. I must say I implemented the threading + Queue module suggestion and it is incredibly simple and elegant. I'm still recovering from the glorious light rays emanating from the Python code. cs -- http://mail.python.org/mailman/listinfo/python-list
logging module -> Miss messages if don't flush constantly? How set to flush constantly?
It looks like I can miss some logging messages if I don't flush after every oneis that true? This is an issue when program crashes so that logger didn't get a chance to print everything. Is there some way to set logging to constantly flush? -- http://mail.python.org/mailman/listinfo/python-list
How *build* new elements and *replace* elements with xml.dom.minidom ?
How build new elements to replace existing ones using xml.dom.minidom? Specifically, I have an HTML table of numbers. I want to replace those numbers with hyperlinks to create a table of hyperlinks. So I need to build hyperlinks (a elements) with href attribute and replace the text elements (numbers) somehow. How do that? chris -- http://mail.python.org/mailman/listinfo/python-list
Where find regexs needed to build lexical analyzer for Python source code?
I'd like to build a lexer aka lexical analyzer aka tokenizer for Python source code as a learning exercise. Where can I find the regexs that define the tokens of Python source? (I am aware of tokenizer.py but I was hoping there was a web page w/ a list somewhere.) cs -- http://mail.python.org/mailman/listinfo/python-list
Where regexs listed for Python language's tokenizer/lexer?
Where regexs listed for Python language's tokenizer/lexer? If I'm not mistaken, the grammar is not sufficient to specify the language you also need to specify the regexs that define the tokens right?..where is that? chris -- http://mail.python.org/mailman/listinfo/python-list