Re: [Tutor] web programming tutorials?

2008-04-19 Thread Alan Gauld
"Monika Jisswel" <[EMAIL PROTECTED]> wrote 

> reading theses emails i have a question :
> ikaaro  or zope - what's best ? which one is the most used ?

They are very different animals as far as I can rtell.

In terms of usage there is nom doubt Zope is more poular, you 
can tell that by the fact that there are several commercial books 
published by mainstream publishers about Zope. I know from 
experiejce that a publisher won't go to print unless they are 
confident they can sell at least several thousand copies.

Howeever Zope is a very big comprehesive web environment, 
much bigger than is needed for the majority of web projects.
My guess is that the most popeular web frameworks just 
now are Django and TurboGears(*), both of which are much 
simpler than Zope but offer much of its convenience. As I 
understand it ikaaro is more directly targetted at the Django 
type user community than Zope. Zope is great if youneed to 
build a big complex web site with many visitors each performing 
complex transactions.

(*)TurboGears is really a package of other framework 
components, most notably CherryPy which has its own 
independant community and so could therefore be argued 
to be most popular if you aggregate TurboGears and 
CherryPy users.

But comparing Zope with ikaaro is not really a sensible 
comparison. Its like comparing Microsoft Access with 
IBM DB2 as databases. They have totally different 
audiences.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Setting the PC Clock to Correct Time

2008-04-19 Thread Wayne Watson
I have a Python program that runs 24/7, but is activated around dusk and 
de-activated from its task around dawn. My clock drifts about 4 sec/day. 
Is there some function that will fetch the correct time from the 
internet and reset the clock? I'd like to reset the clock each time the 
program is activated at dusk.

-- 
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

   "Philosophy is questions that may never be
answered. Religion is answers that may never
be questioned" -- Anon
 
Web Page: 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting the PC Clock to Correct Time

2008-04-19 Thread jay
Wayne,

Is this a Linux box?  If so, you might consider setting up NTP to sync to an
outside time source.  We do that here and it works quite well, even
accounting for drifting.  If this is a Windows machine, I believe those are
already synced with the PDC, if joined to a Domain, but I might be wrong.

Jason

On Sat, Apr 19, 2008 at 10:45 AM, Wayne Watson <[EMAIL PROTECTED]>
wrote:

> I have a Python program that runs 24/7, but is activated around dusk and
> de-activated from its task around dawn. My clock drifts about 4 sec/day.
> Is there some function that will fetch the correct time from the
> internet and reset the clock? I'd like to reset the clock each time the
> program is activated at dusk.
>
> --
>   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
>   "Philosophy is questions that may never be
>answered. Religion is answers that may never
>be questioned" -- Anon
>
>Web Page: 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting the PC Clock to Correct Time

2008-04-19 Thread Chris Fuller
On Saturday 19 April 2008 10:45, Wayne Watson wrote:
> I have a Python program that runs 24/7, but is activated around dusk and
> de-activated from its task around dawn. My clock drifts about 4 sec/day.
> Is there some function that will fetch the correct time from the
> internet and reset the clock? I'd like to reset the clock each time the
> program is activated at dusk.

You need an NTP (network time protocol) client.  You may have one built in to 
your operating system.

Check out http://www.pool.ntp.org/ for tips on how to get started.

Cheers
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting the PC Clock to Correct Time

2008-04-19 Thread Chris Fuller
I just checked my laptop (XP Pro), and you can set the time server (or use the 
default), but it only updates once a week.  So your computer's time could be 
off by thirty seconds by the time of the next synchronization.  It might be 
enough, but you also need to be aware so you aren't confused into thinking it 
isn't working when its off by four seconds the next day.

I used to have my linux desktop synchronize every six hours.  The full blown 
NTP client runs more or less continuously, and can keep you within 
milliseconds of the standard.

Cheers

On Saturday 19 April 2008 10:45, Wayne Watson wrote:
> I have a Python program that runs 24/7, but is activated around dusk and
> de-activated from its task around dawn. My clock drifts about 4 sec/day.
> Is there some function that will fetch the correct time from the
> internet and reset the clock? I'd like to reset the clock each time the
> program is activated at dusk.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing from Python prompt

2008-04-19 Thread kinuthia muchane
Hi,

I do not know what I am doing wrong. When I run the following code from
the Python prompt it executes without a murmur. But when I save it as
a .py file and try to execute it from the shell, it just returns the
prompt...actually it is all scripts that return a value which  are
behaving in this manner.


def factorial(n):
if n <= 1:
  return 1
else:
  return n * factorial(n-1)

factorial(some number here)

The same happens when I use IDLE.

Thanks!
Kinuthia...



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hoping to benefit from someone's experience...

2008-04-19 Thread Marc Tompkins
Just as a followup -  I ended up using a Python script to recurse through
the folders of files and, for each file found, extract the
doctor/date/medical record number from the filename, then run a Word macro
on the file to insert the header slug.

If anyone ever needs to do something similar, or just wants to laugh at what
a hack this turned out to be, I've attached a text file containing the
Python and the macro.  (The UIDs and names have all been sanitized for my
protection.)
Bear in mind that this was a one-off; if I end up re-using this I will clean
it up, put things in classes, load UIDs from an external file, etc.

Background:
In the folder "U:\transcripts.doc"  there are folders called "Recent" and
"Archive" for each of about twelve providers; I need only Able, Baker, Doe,
Roe, Smith and Jones - that's why I put the folder names in a tuple instead
of simply processing the root folder.  Inside of each folder there are
subfolders for individual patients, but also many patient documents in the
main folder.

File names are supposed to follow the format
"Last,First-MRN-01Jan2008-Able.doc",
  but there are many variations on this theme -
"Last,First-01Jan2008-MRN-Able.doc"
"Last,First-MRN-01Jan2008-Able-Echo.doc"
"Last,First-MRN-01Jan2008-Echo-Able.doc"
"Last,First-01Jan2008-MRN-Echo-Able.doc"
"Last,First-01Jan2008-MRN-Able-Echo.doc"
etc.

Last,First - the patient's name.  Irrelevant to my purpose.
MRN - medical record number
Echo - most of these files are consultations, but the ones labeled "Echo"
are echocardiogram reports.  For these I need to set Category and
Description to "Echo"; otherwise it's "Consultation
External"/"Consultation".

The doctor is supposed to dictate the MRN, and the transcriptionist puts it
in the filename - but there are many cases where the MRN is missing.  These
can look like:
"Last,First-XXX-01Jan2008-Able.doc"
"Last,First--01Jan2008-Able.doc"
"Last,First-01Jan2008-Able.doc"
so I needed several different filters

The date needs to be passed in MM/DD/ format; I found that the easiest
way to figure out which field was the date was to try/except strftime().
I'm sure there's a more elegant way using regexp, but I was in
quick-and-dirty mode.

As you might expect, most of the time is spent in Word.  It would probably
be faster if I set Visible = False, but for some reason the macro fails
(silently) when I do that, so I just minimize Word instead to cut down on
screen refreshes.  Also, drive U is a Samba share, so there's network
latency to take into account.  Even so, 10,231 files took less than 15
minutes to convert, which I can live with.

-- 
www.fsrtechnologies.com
#!/usr/bin/python
import os, os.path, sys, time
import logging
from win32com.client import Dispatch

startDirs =("u:/transcripts.doc/ABLE-Recent",
"u:/transcripts.doc/ABLE-Archive",
"u:/transcripts.doc/BAKER-Recent",
"u:/transcripts.doc/BAKER-Archive",
"u:/transcripts.doc/DOE-Recent",
"u:/transcripts.doc/DOE-Archive",
"u:/transcripts.doc/ROE-Recent",
"u:/transcripts.doc/ROE-Archive",
"u:/transcripts.doc/SMITH-Recent",
"u:/transcripts.doc/SMITH-Archive",
"u:/transcripts.doc/JONES-Recent",
"u:/transcripts.doc/JONES-Archive")

targetDir = "U:/xsRTF"


class Global(object):
prov = {
'ABLE':   'F000789F-3001-400F-845B-B0D78B0B000B',
'BAKER':  'B000FBD5-0007-4007-A959-60B63B32000C',
'DOE':'30008D6D-8008-400D-B031-700ECD75000C',
'ROE':'90002DC9-100A-4005-B284-D0763273',
'SMITH':  '7000FD10-5009-4000-9CDB-608FDEF2000F',
'JONES':  'F000DDE8-400E-400C-8B7D-10CE9F5C'}

# There are UIDs for hospitals as well, but I haven't seen any dictations
#   for hospital visits - so I'm assuming everything happened in the office.
# There may be some exceptions, and I may have to clean them up later...
#   but I don't see how I can help it now.
locID = "90001E61-200A-4004-9006-700063790002"

# the only extra description that ever comes up is "Echo", 
#but I put it in a dict just in case I found more
desc = {
'ECHO': ('Echo','Echo'), }
totalFiles = 0
skippedFiles = 0
failedFiles = 0



def doConversion(oldPath):
oldName = os.path.basename(oldPath)
# there are lots of daily roster files - we don't want them
# also lots of orphaned temporary documents...
if oldName.upper().strip().startswith(('ROSTER', '~'),0):
Global.skippedFiles +=1
return
nameParts = oldName.rstrip(".doc").split('-')
# No MRN to be had from "Last,First-Date-Doc.doc" or 
#   "Last,First--Date-Doc.doc"
if  ((len(nameParts) < 4) or (len(nameParts[1]) == 0)): 
logging.error("%s - no MRN" % oldPath)
Global.failedFiles +=1
return

newParts = {}
try:
# filename has date in stan

Re: [Tutor] Executing from Python prompt

2008-04-19 Thread bob gailer
kinuthia muchane wrote:
> Hi,
>
> I do not know what I am doing wrong. When I run the following code from
> the Python prompt it executes without a murmur. But when I save it as
> a .py file and try to execute it from the shell, it just returns the
> prompt...actually it is all scripts that return a value which  are
> behaving in this manner.
>
>
> def factorial(n):
>   if n <= 1:
> return 1
>   else:
> return n * factorial(n-1)
>
> factorial(some number here)
>
>   
print factorial(some number here)

When you enter an expression at the interactive prompt you see the 
value. Not true when you run a program. Expression values must be 
printed. So you are doing nothing wrong.

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting the PC Clock to Correct Time

2008-04-19 Thread Alan Gauld

"Wayne Watson" <[EMAIL PROTECTED]> wrote

Is there some function that will fetch the correct time from the
internet and reset the clock? I'd like to reset the clock each time 
the
program is activated at dusk.

That should be standard in your S.
If its Windows you do it via the Internet Time tab on the
Date & Time applet.


Do you have that set, it should prevent drift by more than a
couple of seconds or so in total.

You can do the same in MacOS or Linux.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing from Python prompt

2008-04-19 Thread Alan Gauld

"kinuthia muchane" <[EMAIL PROTECTED]> wrote

> I do not know what I am doing wrong. When I run the following code 
> from
> the Python prompt it executes without a murmur. But when I save it 
> as
> a .py file and try to execute it from the shell, it just returns the
> prompt...actually it is all scripts that return a value which  are
> behaving in this manner.

The >>> prompt evaluates expressions and prionts the value.
The interpreter on the other hand does not automatically print
values you ghave to explicitly tell it to print using the print
statement.

So in your case just add the print command in front of the
function call and all will be well.

> factorial(some number here)

print factorial(n)

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need help with sockets

2008-04-19 Thread James Duffy
For a part of a program, I need to send a text string to another machine in
a IM style app. I've done this in C# but never in python. The server is in
C# so I just need a client side program that can listen for and display
incoming messages as well as send messages. Ive managed to make a socket and
connect but I don't know how to setup a listen thread and a sender function.
Can someone help? Below is C# code for the listener/send function of my
client that id made. I basically hafta turn this into python. This method
runs inside a thread.

 

 

 

 

void RunClient() 

{

TcpClient myClient; // instantiate TcpClient for sending data to server 

try 

{

Output to screen: Attempting connection\r\n" 

// Step 1: Create TcpClient 

myClient = new TcpClient(); 

// Step 2: Connect to server 

myClient.Connect(address.Text,int.Parse(port.Text)); 

// Step 3: Create a Network Stream associated with TcpClient 

myNetStream = myClient.GetStream();

// Step 4: Create objects for writing and reading across stream 

myWriter = new BinaryWriter(myNetStream); 

myReader = new BinaryReader(myNetStream); 

// loop until server signals termination 

do 

{

// Step 5: Processing phase 

try 

{

// read message from server 

message = myReader.ReadString();

inbound.Text +="\r\n" + message; 

}

// handle exception if error in reading server data 

catch (Exception) 

{

System.Environment.Exit( System.Environment.ExitCode); 

}

} 

while (message != "SERVER>>> TERMINATE"); 

status.Text += "\r\nClosing connection.\r\n"; 

// Step 6: Close connection 

myWriter.Close();

myReader.Close();

myNetStream.Close();

myClient.Close();

Application.Exit(); 

}

// handle exception if error in establishing connection 

Catch (Exception error) 

{

MessageBox.Show(error.ToString()); 

}

}

 

 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Recursion doubt

2008-04-19 Thread Jos Kerc
Hi,

you are tackling 3 "heavy" subjects in just 1 go!

graphs :a triving math society would approve your choice. But you might
start with the *slightly* less difficult challenge: trees.
I do not know your math/programming background, so the following link can
perhaps enlighten you: http://www.brpreiss.com/books/opus7/

Trees, graphs, queues and what more implemented in several languages. Python
included.
Also, most CS starters have chapters devoted to (some of) them.
(E.g. http://www.greenteapress.com/thinkpython/)

Backtracking & recursion will surely be topics too.
 Reading them will help getting a handle on it

The 3 chosen topics are advanced or even rather advanced even for most of CS
people.


To return to your question...
Basically, find_path takes a node connected to 'start', if not at the 'end',
make the current node 'start' and see if find_path does return a path. As
soon as a path is foud find_path quits searching.

You can look at find_all as a master routine that keeps calling find_path
until find_path gives up. If the search space has not been exhausted (here
there are still other nodes connected to 'start') take a suitable candidate
call find_path from there until no more paths from there can be found.
Repeat until no more suitable candidates.

As you have gone through the whole search space, all paths from 'start' to
'end' were found.

Recursion makes backtracking easier: the program/routine will by itself keep
track of the steps taken & where to go back if a search fails.

Backtracking is the powerful technique of remembering the steps already
taken & to retrace them till the first non-explored sidetrack when needed.

Choosing the next non-explored sidetrack though can be complex involving
other searches, ...
It all depends on what you look for, how the data is represented.

A related topic that will help you understand things is breadth-first &
depth-first searches on trees.

(in this case find_path executes a depth-first search on the graph -
represented as a dictionary & find_all combines the 2 searches, first the
depth search & when it quits, the breadth search takes over.)

Greetz

On 4/15/08, Anshu Raval <[EMAIL PROTECTED]> wrote:
>
>  Hi,
> At the url 
> *http://www.python.org/doc/essays/graphs.html*there
>  is some
> code by Guido Van Rossum for computing paths through a graph - I have
> pasted it below for reference -
>
> Let's write a simple function to determine a path between two nodes.
> It takes a graph and the start and end nodes as arguments. It will
> return a list of nodes (including the start and end nodes) comprising
> the path. When no path can be found, it returns None. The same node
> will not occur more than once on the path returned (i.e. it won't
> contain cycles). The algorithm uses an important technique called
> backtracking: it tries each possibility in turn until it finds a
> solution.
>
> def find_path(graph, start, end, path=[]):
> path = path + [start]
> if start == end:
> return path
> if not graph.has_key(start):
> return None
> for node in graph[start]:
> if node not in path:
> newpath = find_path(graph, node, end, path)
> if newpath: return newpath
> return None
>
> *** He then says
>
> It is simple to change this function to return a list of all paths
> (without cycles) instead of the first path it finds:
>
> def find_all_paths(graph, start, end, path=[]):
> path = path + [start]
> if start == end:
> return [path]
> if not graph.has_key(start):
> return []
> paths = []
> for node in graph[start]:
> if node not in path:
> newpaths = find_all_paths(graph, node, end, path)
> for newpath in newpaths:
> paths.append(newpath)
> return paths
>
> *** I couldn't understand how it was simple to change the function
> find paths to find all paths. How would you think about writing this
> second function recursively. Especially the part about if start==end:
> return [path]. I feel you would give square brackets around path here
> after first writing the inductive part ... for node in
> graph[start] 
> and then by trial and error put square brackets around path in the
> Basis part. Can someone please explain how to write this code. Thanks!
>
>
>
>
> --
> Planning marriage in 2008! Join Shaadi.com matrimony FREE! Try it 
> now!
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting the PC Clock to Correct Time

2008-04-19 Thread Dick Moores


At 10:40 AM 4/19/2008, Chris Fuller wrote:
I just checked my laptop (XP
Pro), and you can set the time server (or use the 
default), but it only updates once a week.  So your computer's time
could be 
off by thirty seconds by the time of the next synchronization.  It
might be 
enough, but you also need to be aware so you aren't confused into
thinking it 
isn't working when its off by four seconds the next
day.
Something I'd saved for my Win XP:
===
 If you'd like Windows to synch the time more or less
frequently, you can change the interval by editing the registry. Here's
how:
1. Open your favorite registry editor. 
2. Navigate to the following key in the left pane:
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\W32Time\TimeProviders\NtpClient.

3. In the right pane, double click the entry called SpecialPollInterval.

4. In the Base section of the Edit DWord Value dialog box, click the
Decimal option button. 
5. Enter the desired interval in seconds (3600 = 1 hour, 1800 = 30
minutes, 86400 = 24 hours, and so forth). 
6. Click OK and close the registry editor. 


Dick Moores


  

UliPad <>:

http://code.google.com/p/ulipad/


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help with sockets

2008-04-19 Thread Alan Gauld

"James Duffy" <[EMAIL PROTECTED]> wrote

> C# so I just need a client side program that can listen for and 
> display
> incoming messages as well as send messages. Ive managed to make a 
> socket and
> connect but I don't know how to setup a listen thread and a sender 
> function.

Tale a look at the Network Programming topic in my tutorial.
It has an example of a client sending to a server and listening
for the responses.

Its not threaded though so you'll need to look elsewhere for
the threading code.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor