Re: [Tutor] Using the time module to extract a semi-random number

2009-09-17 Thread Patrick Sabin

Laurii wrote:

Hello all,

I am currently reading through the Tutorial for Non-Programers by Josh 
Cogliati.  I have had great success until now.


The exercise to modify a number guessing program from a fixed number 
"number = 78" to using the time module and use the seconds at the time 
the program is used to be the number. (i.e. if the clock on your 
computer says 7:35:25 then it would take the 25 and place it in "number".




You can either use:

import time
number = int(time.strftime("%S"))

or use real pseudo-random numbers:

import random
number = random.randint(0,59)

The latter looks clearer to me.

- Patrick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing a command from a specific directory

2009-09-17 Thread Ansuman Dash
Hi,

I modified my code little bit and it is working fine now,

=
if os.access("C:/Python25/Own.log", os.F_OK):
f = open("C:/Python25/Own.log")
time.sleep(30)
try:
line = f.readlines()
a = string.join(line)

if "Request timed out.." not in a:
print("Ping is not successful.")
pLogger.info("Ping is not successful.")
else:
print ("Ping is successful.")
pLogger.info("Ping is successful.")

finally:
f.close()
else:
pLogger.info("File doesn't exist")
===

But I have question to ask, as you can see I am using "time.sleep(30)" to
make my code wait. Is there any other way I can write my script to resolve
synchronization issues.

Thanks,
AD

On Thu, Sep 17, 2009 at 12:13 AM, Steve Willoughby wrote:

> > Ansuman Dash wrote:
> > >Now I am trying to validate that the command is executed successfully.
> > >I have written following script to validate the log file which is
> created
> > >after running the command.
>
> Notice what's happening here:
>
> > >for line in f.readlines():
> > >a=line
>
> This sets a to EACH line from the file, overwriting
> the previous one.  What you end up with after that
> executes is a holding the LAST line in the file.
>
> > >if "Request timed out.." not in a:
> > >print("Ping is not successful.")
> > >pLogger.info("Ping is not successful.")
>
> Also... this looks backwards.  If "Request timed out.." is NOT found
> then the ping was NOT successful?
>
> --
> Steve Willoughby|  Using billion-dollar satellites
> st...@alchemy.com   |  to hunt for Tupperware.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] max min value in array

2009-09-17 Thread Rayon
I need to find the max and min value from some floats in a array:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] On slicing

2009-09-17 Thread george fragos
  If numbers=[1,2,3,4,5,6,7,8,9,10] and since "...any time the
leftmost index in a slice comes later in the seqence than the second
one... the result is always an empty sequence", why the slice
numbers[10:0:-2] produces the sequence [10,8,6,4,2] but not the
sequence []?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing a command from a specific directory

2009-09-17 Thread Kent Johnson
On Thu, Sep 17, 2009 at 5:47 AM, Ansuman Dash  wrote:
> Hi,
>
> I modified my code little bit and it is working fine now,
>
> =
>     if os.access("C:/Python25/Own.log", os.F_OK):
>     f = open("C:/Python25/Own.log")
>     time.sleep(30)
> ===
>
> But I have question to ask, as you can see I am using "time.sleep(30)" to
> make my code wait. Is there any other way I can write my script to resolve
> synchronization issues.

How is the log being created? Are you waiting for another process to
finish? You can use the subprocess module to start another process and
then wait for the process to complete.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] max min value in array

2009-09-17 Thread Kent Johnson
On Thu, Sep 17, 2009 at 7:37 AM, Rayon  wrote:
> I need to find the max and min value from some floats in a array:

Did you try the min() and max() functions?

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] max min value in array

2009-09-17 Thread Rich Lovely
2009/9/17 Rayon :
> I need to find the max and min value from some floats in a array:
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

Depending on the size of the array, there's two methods:  Using the
max and min builtin functions, which will be faster for small arrays,
or hand-coding a single pass function, which might be faster for
arrays above a certain size.

def minmax1(a):
#This needs two passes of the array, but uses builtins, which are
written in c, and are therefore faster than the equivalent python
return min(a), max(a)

def minmax2(a):
#This only takes one pass, but is python, which is not as fast as C code.
#This also has the advantage of allowing you to easily customize
your lookups and comparisons
minVal = a[0]
maxVal = a[0]
for v in a:
if v < minVal:
minVal = v
elif v > maxVal:
maxVal = v
return minVal, maxVal

Other techniques to consider:  If order is not important, take the
first and last values after sorting (or after sorting a copy).

You will want to profile each version, to find out what is best in
your specific case.

If you want to return the indexes of the maximum and minimum, you will
need to use the minmax2 function, modified slightly:

def minmaxIndexes(a):
"""returns a tuple of the indexes of the (first) minimum and
maximum in the array"""
minVal = 0, a[0]
maxVal = 0, a[0]
for v in enumerate(a):
if v[1] < minVal[1]:
minVal = v
elif v[1] > maxVal[1]:
maxVal = v
return minVal[0], maxVal[0]


-- 
Rich "Roadie Rich" Lovely

There are 10 types of people in the world: those who know binary,
those who do not, and those who are off by one.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing html tables and using numpy for subsequent processing

2009-09-17 Thread David Kim
>
> Gerard wrote:
> Not very pretty, but I imagine there are very few pretty examples of
> this kind of thing. I'll add more comments...honest. Nothing obviously
> wrong with your code to my eyes.
>

Many thanks gerard, appreciate you looking it over. I'll take a look at the
link you posted as well (I'm traveling at the moment).

Cheers,

-- 
David Kim

"I hear and I forget. I see and I remember. I do and I understand." --
 Confucius

morenotestoself.wordpress.com
financialpython.wordpress.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] On slicing

2009-09-17 Thread Rich Lovely
2009/9/17 george fragos :
>  If numbers=[1,2,3,4,5,6,7,8,9,10] and since "...any time the
> leftmost index in a slice comes later in the seqence than the second
> one... the result is always an empty sequence", why the slice
> numbers[10:0:-2] produces the sequence [10,8,6,4,2] but not the
> sequence []?
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

There should be a caveat to that:  Unless the third index (step) is negative.

The first value is start, the second stop, and the third step.  What
you are saying with numbers[10,0,-2], is start at 10 (facing towards
the end of the sequence), keep going until you get to 0, taking two
steps backwards each time.

I hope that clears things up a little..

-- 
Rich "Roadie Rich" Lovely

There are 10 types of people in the world: those who know binary,
those who do not, and those who are off by one.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] max min value in array

2009-09-17 Thread Kent Johnson
On Thu, Sep 17, 2009 at 8:06 AM, Rich Lovely  wrote:
> 2009/9/17 Rayon :
>> I need to find the max and min value from some floats in a array:

> Depending on the size of the array, there's two methods:  Using the
> max and min builtin functions, which will be faster for small arrays,
> or hand-coding a single pass function, which might be faster for
> arrays above a certain size.

Why do you expect a hand-coded function to scale better? I would
expect them both to be O(n).

> def minmax2(a):
>    #This only takes one pass, but is python, which is not as fast as C code.
>    #This also has the advantage of allowing you to easily customize
> your lookups and comparisons

min() and max() both take key= parameters allowing you to customize
the comparison.

> Other techniques to consider:  If order is not important, take the
> first and last values after sorting (or after sorting a copy).

Sorting is O(n log n) so this will have relatively worse performance
with larger arrays.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-17 Thread ad...@gg-lab.net
Thankyou all, you're very precious for me.

yeah it seems the development webserver (and the production one) are
importing modules in a non-standard way.

I absolutely don't understand this choice. Why import everything
everytime? Don't you think it makes scripts much more slow?

Giorgio

2009/9/16 Kent Johnson :
> On Sun, Sep 13, 2009 at 9:59 AM, ad...@gg-lab.net  wrote:
>> Hi All,
>>
>> i've started earning python sone months ago (on Google App Engine
>> unfortunately).
>>
>> I have some doubts reagrding "import", and have asked a similar
>> question here months ago, but without finding a solution.
>>
>> So:
>>
>> with import i can import modules or single functions. And this is ok.
>> Then: as i have understood from all the books i readm in each package
>> directory i have the __init__.py file that decides what import with
>> it. In other words if my package skel is like:
>>
>> /gg/
>> /gg/sub1/
>> /gg/sub1/file.py
>> /gg/sub2/
>> /gg/sub2/file.py
>>
>> and i use "import gg", nothing is imported. To import sub1 and sub2, i can:
>>
>> - Put in /gg/ a __init__.py file that tells to import them
>> - Use "from gg import sub1"
>>
>> Ok now the $1 Billion question: google app engine has the same schema
>> than my "gg" package, an empty __init__.py file, but if i use "import
>> google" it also imports all subdirectories. And i can't understand
>> wiìhy it does so.
>
> In general,
>  import foo
> does not import subpackages of foo unless they are specifically
> imported in foo/__init__.py, so dir(foo) will not show the
> subpackages.
>
> However if you
>  import foo
>  import foo.bar
> then dir(foo) will include 'bar'. Here is an example from the std lib:
>
> In [1]: import distutils
>
> In [2]: dir(distutils)
> Out[2]:
> ['__builtins__',
>  '__doc__',
>  '__file__',
>  '__name__',
>  '__package__',
>  '__path__',
>  '__revision__',
>  '__version__']
>
> In [3]: import distutils.cmd
>
> In [4]: dir(distutils)
> Out[4]:
> ['__builtins__',
>  '__doc__',
>  '__file__',
>  '__name__',
>  '__package__',
>  '__path__',
>  '__revision__',
>  '__version__',
>  'archive_util',
>  'cmd',
>  'dep_util',
>  'dir_util',
>  'errors',
>  'file_util',
>  'log',
>  'spawn',
>  'util']
>
> My guess is that the startup for GAE is importing the subpackages so
> they then appear as imported modules. To access your sub-package, just
> import it normally.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing a command from a specific directory

2009-09-17 Thread Ansuman Dash
I am using same process for multiple file download. So I need to download
those one by one.

Moreover some files are very huge (around 120 MB). So I need to make script
to wait before verifying the file is downloaded.

Thanks
AD

On Thu, Sep 17, 2009 at 5:34 PM, Kent Johnson  wrote:

> On Thu, Sep 17, 2009 at 5:47 AM, Ansuman Dash 
> wrote:
> > Hi,
> >
> > I modified my code little bit and it is working fine now,
> >
> > =
> > if os.access("C:/Python25/Own.log", os.F_OK):
> > f = open("C:/Python25/Own.log")
> > time.sleep(30)
> > ===
> >
> > But I have question to ask, as you can see I am using "time.sleep(30)" to
> > make my code wait. Is there any other way I can write my script to
> resolve
> > synchronization issues.
>
> How is the log being created? Are you waiting for another process to
> finish? You can use the subprocess module to start another process and
> then wait for the process to complete.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-17 Thread Kent Johnson
On Thu, Sep 17, 2009 at 8:38 AM, ad...@gg-lab.net  wrote:
> Thankyou all, you're very precious for me.
>
> yeah it seems the development webserver (and the production one) are
> importing modules in a non-standard way.
>
> I absolutely don't understand this choice. Why import everything
> everytime? Don't you think it makes scripts much more slow?

My guess is that they are importing what they need. It does impact
startup but hey, if you need it, you need it.

Try this for comparison: Start Python from a command line, then
In [5]: import sys

In [6]: len(sys.modules)
Out[6]: 323

I have IPython loaded so this number may be larger than yours. In
Python 3, with no IPython, I get
>>> import sys
>>> len(sys.modules)
47

So my advice is, don't worry about it.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing a command from a specific directory

2009-09-17 Thread Kent Johnson
On Thu, Sep 17, 2009 at 8:40 AM, Ansuman Dash  wrote:
> I am using same process for multiple file download. So I need to download
> those one by one.
>
> Moreover some files are very huge (around 120 MB). So I need to make script
> to wait before verifying the file is downloaded.

I don't understand how you are downloading the files. Can you show some code?

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ImportError: cannot import name log

2009-09-17 Thread steve

Hello Vishwajeet,

On 09/16/2009 11:21 PM, vishwajeet singh wrote:

Hi,

Below is the content of __init__.py

import sys
from django.core.signals import got_request_exception
from . import log
logger = log._get_logger()

def got_request_exception_callback(sender, **kwargs):
"""Logging all unhandled exceptions."""
 type, exception, traceback = sys.exc_info()
 logger.error(unicode(exception))
got_request_exception.connect(got_request_exception_callback)

My question here is that what does *from . import log* doing I can see a
module name log in the same folder.


The '.' notation is fairly new and also uncommon AFAIK
http://docs.python.org/tutorial/modules.html#intra-package-references


This import statement is throwing an error ImportError: cannot import
name log.
The reasons it can't import using this 'from . import' notation would be the 
same as for any other import errors. Check your PYTHONPATH and paste the entire 
traceback if it still does not work.


cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] html color coding: where to start

2009-09-17 Thread عماد نوفل
Hi Tutors,
I want to color-code the different parts of the word in a morphologically
complex natural language. The file I have looks like this, where the fisrt
column is the word, and the  second is the composite part of speech tag. For
example, Al is a DETERMINER, wlAy is a NOUN and At is a PLURAL NOUN SUFFIX

Al+wlAy+AtDET+NOUN+NSUFF_FEM_PL
Al+mtHd+pDET+ADJ+NSUFF_FEM_SG

The output I want is one on which the word has no plus signs, and each
segment is color-coded with a grammatical category. For example, the noun is
red, the det is green, and the suffix is orange.  Like on this page here:
http://docs.google.com/View?id=df7jv9p9_3582pt63cc4
I am stuck with the html part and I don't know where to start. I have no
experience with html, but I have this skeleton (which may not be the right
thing any way)
Any help with materials, modules, suggestions appreciated.

This skeleton of my program is as follows:

#
RED = ("NOUN", "ADJ")
GREEN = ("DET", "DEMON")
ORANGE = ("NSUFF", "VSUFF", "ADJSUFF")
# print html head
def print_html_head():
#print the head of the html page

def print_html_tail():
   # print the tail of the html page

def color(segment, color):
   # STUCK HERE shoudl take a color, and a segment for example

# main
import sys
infile = open(sys.argv[1]) # takes as input the POS-tagged file
print_html_head()
for line in infile:
line = line.split()
if len(line) != 2: continue
word = line[0]
pos = line[1]
zipped = zip(word.split("+"), pos.split("+"))

for x, y in zipped:
if y in DET:
color(x, "#FF")
else:
color(x, "#FF")


print_html_tail()




-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ImportError: cannot import name log

2009-09-17 Thread vishwajeet singh
On Thu, Sep 17, 2009 at 8:41 PM, steve  wrote:

> Hello Vishwajeet,
>
> On 09/16/2009 11:21 PM, vishwajeet singh wrote:
>
>> Hi,
>>
>> Below is the content of __init__.py
>>
>> import sys
>> from django.core.signals import got_request_exception
>> from . import log
>> logger = log._get_logger()
>>
>> def got_request_exception_callback(sender, **kwargs):
>> """Logging all unhandled exceptions."""
>> type, exception, traceback = sys.exc_info()
>> logger.error(unicode(exception))
>> got_request_exception.connect(got_request_exception_callback)
>>
>> My question here is that what does *from . import log* doing I can see a
>> module name log in the same folder.
>>
>>  The '.' notation is fairly new and also uncommon AFAIK
> http://docs.python.org/tutorial/modules.html#intra-package-references
>
>  This import statement is throwing an error ImportError: cannot import
>> name log.
>>
> The reasons it can't import using this 'from . import' notation would be
> the same as for any other import errors. Check your PYTHONPATH and paste the
> entire traceback if it still does not work.
>
> cheers,
> - steve
>
> --
> random non tech spiel: http://lonetwin.blogspot.com/
> tech randomness: http://lonehacks.blogspot.com/
> what i'm stumbling into: http://lonetwin.stumbleupon.com/
>

Thanks steve for your help I was able to fix the probelm.

-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] max min value in array

2009-09-17 Thread Kent Johnson
On Thu, Sep 17, 2009 at 11:01 AM, steve  wrote:
> On 09/17/2009 06:04 PM, Kent Johnson wrote:
>>
>> On Thu, Sep 17, 2009 at 8:06 AM, Rich Lovely
>>  wrote:
>>>
>>>  2009/9/17 Rayon:

  I need to find the max and min value from some floats in a array:
>>
>>>  Depending on the size of the array, there's two methods:  Using the
>>>  max and min builtin functions, which will be faster for small arrays,
>>>  or hand-coding a single pass function, which might be faster for
>>>  arrays above a certain size.
>>
>> Why do you expect a hand-coded function to scale better? I would
>> expect them both to be O(n).
>>
> I guess what Rich meant was, a hand-coded function to get /both/ min and max
> in a single pass would be faster on large arrays (as done in the posted
> minmax2() function) than calling min() and max() individually (which would
> imply 2 passes).

Yes, that is my understanding of his statement. My question is, why
would it be faster only on large arrays? I expect the time of both
methods to scale linearly with the size of the array. Two fast passes
might be faster than one slow pass regardless of the size of the
array.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html color coding: where to start

2009-09-17 Thread Kent Johnson
2009/9/17 Emad Nawfal (عماد نوفل) :
> Hi Tutors,
> I want to color-code the different parts of the word in a morphologically
> complex natural language. The file I have looks like this, where the fisrt
> column is the word, and the  second is the composite part of speech tag. For
> example, Al is a DETERMINER, wlAy is a NOUN and At is a PLURAL NOUN SUFFIX
>
> Al+wlAy+At    DET+NOUN+NSUFF_FEM_PL
> Al+mtHd+p    DET+ADJ+NSUFF_FEM_SG
>
> The output I want is one on which the word has no plus signs, and each
> segment is color-coded with a grammatical category. For example, the noun is
> red, the det is green, and the suffix is orange.  Like on this page here:
> http://docs.google.com/View?id=df7jv9p9_3582pt63cc4
> I am stuck with the html part and I don't know where to start. I have no
> experience with html, but I have this skeleton (which may not be the right
> thing any way)

Doing a "view source" on that page shows, in part
AlwlAyAtAlmtHdp

which should give you a hint on the HTML though you would be better
off using CSS styling. If you use the part of speech as the CSS class
then you can color with a stylesheet that defines the colors for each
part of speech.

You are probably going to have to learn at least a little HTML to do
this - google HTML tutorial.

This recent package looks like a simple way to generate HTML programmatically:
http://pypi.python.org/pypi/html/1.4

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html color coding: where to start

2009-09-17 Thread Alan Gauld


"Emad Nawfal (عماد نوفل)"  wrote

column is the word, and the  second is the composite part of speech tag. 
For
example, Al is a DETERMINER, wlAy is a NOUN and At is a PLURAL NOUN 
SUFFIX


Al+wlAy+AtDET+NOUN+NSUFF_FEM_PL
Al+mtHd+pDET+ADJ+NSUFF_FEM_SG


I'd create a dictionary with the parts of speech as keys and the colors(as 
html strings) as values.


I'd then arrange your data into tuples of (wordpart, speechpart)
So
('Al', DET)('wlAy',NOUN)

Then you can print with
for item in tuples:
   htmlstr += colors[item[1]] + item[0]   # might need to add a closing 
tag too...


Does that help?

Alan G. 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html color coding: where to start

2009-09-17 Thread bob gailer

Emad Nawfal (عماد نوفل) wrote:

Hi Tutors,
I want to color-code the different parts of the word in a 
morphologically complex natural language. The file I have looks like 
this, where the fisrt column is the word, and the  second is the 
composite part of speech tag. For example, Al is a DETERMINER, wlAy is 
a NOUN and At is a PLURAL NOUN SUFFIX


Al+wlAy+AtDET+NOUN+NSUFF_FEM_PL
Al+mtHd+pDET+ADJ+NSUFF_FEM_SG

The output I want is one on which the word has no plus signs, and each 
segment is color-coded with a grammatical category. For example, the 
noun is red, the det is green, and the suffix is orange.  Like on this 
page here:

http://docs.google.com/View?id=df7jv9p9_3582pt63cc4
I am stuck with the html part and I don't know where to start. I have 
no experience with html, but I have this skeleton (which may not be 
the right thing any way)

Any help with materials, modules, suggestions appreciated.

This skeleton of my program is as follows:

#
RED = ("NOUN", "ADJ")
GREEN = ("DET", "DEMON")
ORANGE = ("NSUFF", "VSUFF", "ADJSUFF")


Instead of that use a dictionary:

colors = dict(NOUN="RED", ADJ="RED",DET ="GREEn",DEMON ="GREEN",
 NSUFF="ORANGE", VSUFF="ORANGE", ADJSUFF="ORANGE")

# print html head
def print_html_head():
#print the head of the html page
   
def print_html_tail():

   # print the tail of the html page

def color(segment, color):
   # STUCK HERE shoudl take a color, and a segment for example

# main
import sys
infile = open(sys.argv[1]) # takes as input the POS-tagged file
print_html_head()
for line in infile:
line = line.split()
if len(line) != 2: continue
word = line[0]
pos = line[1]
zipped = zip(word.split("+"), pos.split("+"))
   
for x, y in zipped:

if y in DET:
color(x, "#FF")
else:
color(x, "#FF")
   

print_html_tail()   





--
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه 
كالحقيقة.محمد الغزالي

"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  



--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] max min value in array

2009-09-17 Thread Rich Lovely
2009/9/17 Kent Johnson :
> On Thu, Sep 17, 2009 at 11:01 AM, steve  wrote:
>> On 09/17/2009 06:04 PM, Kent Johnson wrote:
>>>
>>> On Thu, Sep 17, 2009 at 8:06 AM, Rich Lovely
>>>  wrote:

  2009/9/17 Rayon:
>
>  I need to find the max and min value from some floats in a array:
>>>
  Depending on the size of the array, there's two methods:  Using the
  max and min builtin functions, which will be faster for small arrays,
  or hand-coding a single pass function, which might be faster for
  arrays above a certain size.
>>>
>>> Why do you expect a hand-coded function to scale better? I would
>>> expect them both to be O(n).
>>>
>> I guess what Rich meant was, a hand-coded function to get /both/ min and max
>> in a single pass would be faster on large arrays (as done in the posted
>> minmax2() function) than calling min() and max() individually (which would
>> imply 2 passes).
>
> Yes, that is my understanding of his statement. My question is, why
> would it be faster only on large arrays? I expect the time of both
> methods to scale linearly with the size of the array. Two fast passes
> might be faster than one slow pass regardless of the size of the
> array.
>
> Kent
>

Hmm... I obviously didn't sprinkle round enough hints of my
uncertainty in the matter.  I did, however, suggest that the OPer
profiles both to check.  I was assuming that would cover all the
bases.  Even if I do provide full, working functions, I'm not going to
spoon feed anyone a "fait accomplis".

I'm still learning too...  hence the 'tutor' mailing list, not the
'expert' mailing list.

Perhaps I was wrong on which would be faster, to be honest, I don't
care that much:  if anyone is really worried about speed, they're
using the wrong language.

Perhaps that's the wrong stance to take, but again, I don't care that much.

I always try to make it clear when I'm not certain about a matter.  If
I have ever misled anyone, I can only apologise.

-- 
Rich "Roadie Rich" Lovely

There are 10 types of people in the world: those who know binary,
those who do not, and those who are off by one.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using the time module to extract a semi-random number

2009-09-17 Thread Alan Gauld


"Patrick Sabin"  wrote


import random
number = random.randint(0,59)

The latter looks clearer to me.


Me too, but if the object is to get the learner using the 
time module it doesn't help! :-)


But if the object is really to get a random number then
its much better...

Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html color coding: where to start

2009-09-17 Thread عماد نوفل
2009/9/17 bob gailer 

> Emad Nawfal (عماد نوفل) wrote:
>
>> Hi Tutors,
>> I want to color-code the different parts of the word in a morphologically
>> complex natural language. The file I have looks like this, where the fisrt
>> column is the word, and the  second is the composite part of speech tag. For
>> example, Al is a DETERMINER, wlAy is a NOUN and At is a PLURAL NOUN SUFFIX
>>
>> Al+wlAy+AtDET+NOUN+NSUFF_FEM_PL
>> Al+mtHd+pDET+ADJ+NSUFF_FEM_SG
>>
>> The output I want is one on which the word has no plus signs, and each
>> segment is color-coded with a grammatical category. For example, the noun is
>> red, the det is green, and the suffix is orange.  Like on this page here:
>> http://docs.google.com/View?id=df7jv9p9_3582pt63cc4
>> I am stuck with the html part and I don't know where to start. I have no
>> experience with html, but I have this skeleton (which may not be the right
>> thing any way)
>> Any help with materials, modules, suggestions appreciated.
>>
>> This skeleton of my program is as follows:
>>
>> #
>> RED = ("NOUN", "ADJ")
>> GREEN = ("DET", "DEMON")
>> ORANGE = ("NSUFF", "VSUFF", "ADJSUFF")
>>
>
> Instead of that use a dictionary:
>
> colors = dict(NOUN="RED", ADJ="RED",DET ="GREEn",DEMON ="GREEN",
> NSUFF="ORANGE", VSUFF="ORANGE", ADJSUFF="ORANGE")
>
>> # print html head
>> def print_html_head():
>>#print the head of the html page
>>   def print_html_tail():
>>   # print the tail of the html page
>>
>> def color(segment, color):
>>   # STUCK HERE shoudl take a color, and a segment for example
>>
>> # main
>> import sys
>> infile = open(sys.argv[1]) # takes as input the POS-tagged file
>> print_html_head()
>> for line in infile:
>>line = line.split()
>>if len(line) != 2: continue
>>word = line[0]
>>pos = line[1]
>>zipped = zip(word.split("+"), pos.split("+"))
>>  for x, y in zipped:
>>if y in DET:
>>color(x, "#FF")
>>else:
>>color(x, "#FF")
>>
>> print_html_tail()
>>
>>
>>
>> --
>> لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
>> الغزالي
>> "No victim has ever been more repressed and alienated than the truth"
>>
>> Emad Soliman Nawfal
>> Indiana University, Bloomington
>> 
>> 
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Bob Gailer
> Chapel Hill NC
> 919-636-4239
>

Thank you all. This is great help. I just started looking into html two days
ago.
Thank you again.

-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Trying to Understand GAE

2009-09-17 Thread ad...@gg-lab.net
Yes Kent, i'm not worrying about it, i was just trying to find the
reason why they're doing so.

Anyway, i'm a newbye, but the GAE Evinronment is very very difficult
to understand. The only thing is thas in common with the real python
is the sintax.

Thankyou again

2009/9/17 Kent Johnson :
> On Thu, Sep 17, 2009 at 8:38 AM, ad...@gg-lab.net  wrote:
>> Thankyou all, you're very precious for me.
>>
>> yeah it seems the development webserver (and the production one) are
>> importing modules in a non-standard way.
>>
>> I absolutely don't understand this choice. Why import everything
>> everytime? Don't you think it makes scripts much more slow?
>
> My guess is that they are importing what they need. It does impact
> startup but hey, if you need it, you need it.
>
> Try this for comparison: Start Python from a command line, then
> In [5]: import sys
>
> In [6]: len(sys.modules)
> Out[6]: 323
>
> I have IPython loaded so this number may be larger than yours. In
> Python 3, with no IPython, I get
 import sys
 len(sys.modules)
> 47
>
> So my advice is, don't worry about it.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Simple Program

2009-09-17 Thread Corey Richardson
I'm going to be making a simple program, that is a few books like "A is 
for...", "B is for...", but it will be many built into one, with a some 
sort of define(word) command, some sort of a find(word) command, and a 
few others. Looking for people to contribute, and make this a community 
thing, maybe each doing our own small 'chapter' or the 'book'. I also 
don't know if it is quite appropriate for this list, so forgive me if it 
isn't, and ignore it. Also, Alan, your tutorial is the bomb! Some of the 
simpler things I've seen done better, but you do an amazing job with it. 
It helps alot!
<>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] On slicing

2009-09-17 Thread george fragos
2009/9/17 Rich Lovely :
> 2009/9/17 george fragos :
>>  If numbers=[1,2,3,4,5,6,7,8,9,10] and since "...any time the
>> leftmost index in a slice comes later in the seqence than the second
>> one... the result is always an empty sequence", why the slice
>> numbers[10:0:-2] produces the sequence [10,8,6,4,2] but not the
>> sequence []?
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> There should be a caveat to that:  Unless the third index (step) is negative.
>
> The first value is start, the second stop, and the third step.  What
> you are saying with numbers[10,0,-2], is start at 10 (facing towards
> the end of the sequence), keep going until you get to 0, taking two
> steps backwards each time.
>
> I hope that clears things up a little..
>
> --
> Rich "Roadie Rich" Lovely
>
> There are 10 types of people in the world: those who know binary,
> those who do not, and those who are off by one.
>

Thanx for your reply...!
By the way, I'd like to say hallo to the List and state that I'm just
starting with Python...!

George Fragos
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple Program

2009-09-17 Thread Alan Gauld


"Corey Richardson"  wrote


I'm going to be making a simple program, that is a few books like "A is
for...", "B is for...", but it will be many built into one,


Sorry, I don't understand?


sort of define(word) command, some sort of a find(word) command, and a
few others.


That's fine, although technically those will be functions not commands.
But that's nit picking :-)



isn't, and ignore it. Also, Alan, your tutorial is the bomb! Some of the
simpler things I've seen done better, but you do an amazing job with it.


Thanks for the kind words. If you can offer ideas for improvement I'm 
always

happy to hear. Thats how it improves! And since I;m still working on the
latest update for v3 its a good time for suggestions!

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html color coding: where to start

2009-09-17 Thread Kent Johnson
2009/9/17 Emad Nawfal (عماد نوفل) :
> Hi Tutors,
> I want to color-code the different parts of the word in a morphologically
> complex natural language. The file I have looks like this, where the fisrt
> column is the word, and the  second is the composite part of speech tag. For
> example, Al is a DETERMINER, wlAy is a NOUN and At is a PLURAL NOUN SUFFIX
>
> Al+wlAy+At    DET+NOUN+NSUFF_FEM_PL
> Al+mtHd+p    DET+ADJ+NSUFF_FEM_SG
>
> The output I want is one on which the word has no plus signs, and each
> segment is color-coded with a grammatical category. For example, the noun is
> red, the det is green, and the suffix is orange.  Like on this page here:
> http://docs.google.com/View?id=df7jv9p9_3582pt63cc4

Here is an example that duplicates your google doc and generates
fairly clean, idiomatic HTML. It requires the HTML generation package
from
http://pypi.python.org/pypi/html/1.4

from html import HTML

lines = '''
Al+wlAy+AtDET+NOUN+NSUFF_FEM_PL
Al+mtHd+pDET+ADJ+NSUFF_FEM_SG
'''.splitlines()

# Define colors in a CSS stylesheet
styles = '''
.NOUN
{color: red }

.ADJ
{color: brown }

.DET
{color: green}

.NSUFF_FEM_PL, .NSUFF_FEM_SG
{color: blue}
'''

h = HTML()

with h.html:
with h.head:
h.title("Example")
h.style(styles)

with h.body(newlines=True):
for line in lines:
line = line.split()
if len(line) != 2: continue
word = line[0]
pos = line[1]
zipped = zip(word.split("+"), pos.split("+"))

for part, kind in zipped:
h.span(part, klass=kind)
h.br

print h


Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PyCon 2010 (Atlanta) Call For Tutorials

2009-09-17 Thread Greg Lindstrom
The period to submit proposals for PyCon 2010 in Atlanta is open until
October 18th.  Tutorial are held the two days prior to the main conference
and feature 3-hour classes led by fellow Python developers and
enthusiasts *just
like you*.  Any topic relating to Python is allowed and the organizers
encourage anyone who wants to share their knowledge to submit their ideas
for consideration.  Perennial classes include "Introduction to Python" for
various audiences (beginners, programmers, those new to Django and web
frameworks, etc.), intermediate Python (standard library, module/packages,
objects, etc.) and more specialized topics (SciPy/Matlab, unit and web
testing, optimization) as well as general topics such as "Best Practices"
for web programming, objects, libraries.  There is even interest in a class
to show how to organize, design, write and distribute an Open Source
project.  Any topic relating to Python is eligible.

Tutorial teachers are paid $1,000.00 per class for their efforts.

Interested (we hope so!)?  More information is available at
http://us.pycon.org/2010/tutorials/proposals/  or write us at
pycon-tutori...@python.org.

We look forward to hearing from YOU.

Greg Lindstrom
Tutorial Coordinator, PyCon 2010 (Atlanta)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing a command from a specific directory

2009-09-17 Thread Ansuman Dash
I am downloading files using various command (because files are different)
meant for a executable.

So I have created event driven program to download these files one by one.
But some files are very huge so I want to know how can I synchronize it with
my code.

That means I want to make my code wait for the complete download of that
file and then I ll read the log file and validate that download is
successful.

Thanks,
AD

On Thu, Sep 17, 2009 at 7:02 PM, Kent Johnson  wrote:

> On Thu, Sep 17, 2009 at 8:40 AM, Ansuman Dash 
> wrote:
> > I am using same process for multiple file download. So I need to download
> > those one by one.
> >
> > Moreover some files are very huge (around 120 MB). So I need to make
> script
> > to wait before verifying the file is downloaded.
>
> I don't understand how you are downloading the files. Can you show some
> code?
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing a command from a specific directory

2009-09-17 Thread Lie Ryan

Ansuman Dash wrote:
I am downloading files using various command (because files are 
different) meant for a executable.


What is "various commands"? Are you using wget/curl or similar 
command-line downloader programs? Or are you using a python-based script 
(that uses urllib)? Or are you using a GUI-based downloader?


Then how do you invoke those "various commands"? Are you using a 
separate python and subprocess/popen to invoke them? Or are you using 
shell script? Or do you start them manually?


So I have created event driven program to download these files one by 
one. But some files are very huge so I want to know how can I 
synchronize it with my code. 


Can you modify this "event driven program" so it would call your script 
when the files finished downloading?


That means I want to make my code wait for the complete download of that 
file and then I ll read the log file and validate that download is 
successful.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor