Instead of deciding between Python or Lisp for a programming intro course...What about an intro course that uses *BOTH*? Good idea?

2015-05-10 Thread Chris Seberino
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: Is Python really Lisp without parentheses? So would it be easy to *implement* a lot of Python in Scheme/Lisp?

2014-01-04 Thread Chris Seberino
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


Is Python really Lisp without parentheses? So would it be easy to *implement* a lot of Python in Scheme/Lisp?

2014-01-03 Thread Chris Seberino
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?

2014-01-03 Thread Chris Seberino

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?

2014-01-03 Thread Chris Seberino
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


logging module - Miss messages if don't flush constantly? How set to flush constantly?

2010-08-21 Thread Chris Seberino
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


Re: Possible to make subprocess.Popen jobs run serially rather than in parallel?

2010-06-16 Thread Chris Seberino
On Jun 15, 2:03 pm, Stephen Hansen me+list/pyt...@ixokai.io 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?

2010-06-16 Thread Chris Seberino
On Jun 16, 11:27 am, Stephen Hansen me+list/pyt...@ixokai.io wrote:
 On 6/16/10 7:04 AM, Chris Seberino wrote:

  On Jun 15, 2:03 pm, Stephen Hansen me+list/pyt...@ixokai.io 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


Re: newbie subprocess.Popen performance issues/questions

2010-06-15 Thread Chris Seberino
On Jun 15, 2:44 am, News123 news1...@free.fr 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  = 'pAdded the databasenbsp;span class=status\w
+_DB_/sp'
TIMEOUT = 12
WP_DIR  = os.path.dirname(__file__) + /wordpress

# Get the inputs.
user_name = sys.argv[1]
cpanel_password   = sys.argv[2]
primary_domain= sys.argv[3]
wp_admin_password = sys.argv[4]
wp_admin_email= sys.argv[5]
wp_db_password= sys.argv[6]
wp_akismet_key= sys.argv[7]
wp_adsense_id = sys.argv[8]
title = sys.argv[9]
description   = sys.argv[10]
keywords  = sys.argv[11]
domain= sys.argv[12]
post_title= sys.argv[13]
post_text = sys.argv[14]
theme = sys.argv[15]
auto_log  = sys.argv[16]

# Initialize the output variable.
output = 

# Initialize the Mechanize browser.
browser = mechanize.Browser()

# Perform authentication for the Mechanize browser.
browser.open(HOSTMONSTER_URL + /cgi-bin/cplogin)
browser.select_form(l_login_form)
browser[ldomain] = user_name
browser[lpass]   = cpanel_password
response = browser.submit()
browser.open(response.geturl())
browser.select_form(the_form)
response = browser.submit()

# Go to the databases page.
browser.open(response.geturl())
link = browser.find_link(text_regex = ^MySQL.*Databases$)
response = browser.follow_link(link)
browser.open(response.geturl())

# Create the database and log a report.
database = domain.replace(., )
browser.select_form(mainform)
browser[db] = database
response  = browser.submit()
success_db= SUCCESS_DB.replace(_DB_, database)
if re.search(success_db, response.get_data()):
output += domain +  database creation: SUCCESS + \n
else:
output += domain +  database creation: FAIL + \n
open(auto_log, a).write(output.split(\n)[-2])

# Close the Mechanize browser.
browser.close()

# Initialize the Selenium browser.  (Hostmonster)
browser = selenium.selenium(localhost,
SELENIUM_PORT,
*chrome,
HOSTMONSTER_URL)
browser.start()

# Perform authentication for the Selenium browser.  (HostMonster)
browser.open(/cgi/hosting/assign)
browser.type(ldomain, user_name)
browser.type(lpass,   cpanel_password)
browser.click(//inp...@value = 'LOGIN'])
browser.wait_for_page_to_load(TIMEOUT)

# Assign the domain and log a report.
browser.type(domain, domain)
browser.type(dir,domain)
browser.type(sub,domain.replace(., -))
browser.click(//inp...@value = 'Add Domain'])
browser.wait_for_page_to_load(TIMEOUT)
success_domain = SUCCESS_DOMAIN.replace(_DOMAIN_, domain)
if success_domain in browser.get_html_source():
output += domain +  domain assignment: SUCCESS + \n
else:
output += domain +  domain assignment: FAIL + \n
open(auto_log, a).write(output.split(\n)[-2])

# Close the Selenium browser.  (Hostmonster)
browser.stop()

# Initialize the WordPress instance and log a report.
expect_output  = subprocess.Popen([WP_DIR + /wp_rsync_expect,
   user_name,
   cpanel_password,
   primary_domain],
  stdout = subprocess.PIPE,
  stderr =
subprocess.STDOUT).communicate()[0]
expect_output += subprocess.Popen([WP_DIR + /wp_set_up_expect,
   user_name,
   cpanel_password,
   primary_domain,
   wp_db_password,
   domain,
   theme],
  stdout = subprocess.PIPE,
  stderr =
subprocess.STDOUT).communicate()[0]
if expect_output.strip().endswith(SUCCESS):
output += domain + 

Possible to make subprocess.Popen jobs run serially rather than in parallel?

2010-06-15 Thread Chris Seberino
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


newbie subprocess.Popen performance issues/questions

2010-06-14 Thread Chris Seberino
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: How do subprocess.Popen(ls | grep foo, shell=True) with shell=False?

2010-06-10 Thread Chris Seberino
On Jun 10, 6:52 am, Nobody nob...@nowhere.com 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 defunct 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


How do subprocess.Popen(ls | grep foo, shell=True) with shell=False?

2010-06-09 Thread Chris Seberino
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.sub question (regular expressions)

2009-10-16 Thread Chris Seberino
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


Where find regexs needed to build lexical analyzer for Python source code?

2009-09-11 Thread Chris Seberino
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


How *build* new elements and *replace* elements with xml.dom.minidom ?

2009-06-10 Thread Chris Seberino
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