Re: [Tutor] Help with OCR

2011-02-07 Thread Alan Gauld

Sriram Jaju ramjaju.m...@gmail.com wrote


I'm new to python. I'm doing a project on OCR (Optical Character
Recognition), I've heard a lot about Python so i want to know 
whether i can

use python for OCR.


That depends a lot on the environment. What OS will you be using?
What are you doing exactly? Are you actually reading the characters
optically or are you taking a feed from an OCR device? Are you
processing a scanned image?


If yes what are the tool require for that?.


It depends on the above indformation.

My another doubt is that, can i use python for programming 
microcontrollers


Not normally, but if you can find a program that can program
the microcontroller you might be able to drive it from Python.
Or if the micro has an interface that can be driven from, for example,
a serial port you may be able to do something.

We can't give specific answers without a lot more specific 
information.


--
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] Help with OCR

2011-02-07 Thread Alan Gauld


Shashwat Anand anand.shash...@gmail.com wrote

My another doubt is that, can i use python for programming 
microcontrollers


You bet.


Really? How would he go about that?
I've not seen (or even heard of) Python used in that role before.

Alan G 



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


Re: [Tutor] Help with OCR

2011-02-07 Thread Sriram Jaju
I'm using windows7. I'm doing a robotic project in which a robot has to take
instruction from images which are taken by camera.
image consists of characters like 'START', 'STOP' etc.

On Mon, Feb 7, 2011 at 2:25 PM, Alan Gauld alan.ga...@btinternet.comwrote:

 Sriram Jaju ramjaju.m...@gmail.com wrote

  I'm new to python. I'm doing a project on OCR (Optical Character
 Recognition), I've heard a lot about Python so i want to know whether i
 can
 use python for OCR.


 That depends a lot on the environment. What OS will you be using?
 What are you doing exactly? Are you actually reading the characters
 optically or are you taking a feed from an OCR device? Are you
 processing a scanned image?


  If yes what are the tool require for that?.


 It depends on the above indformation.


  My another doubt is that, can i use python for programming
 microcontrollers


 Not normally, but if you can find a program that can program
 the microcontroller you might be able to drive it from Python.
 Or if the micro has an interface that can be driven from, for example,
 a serial port you may be able to do something.

 We can't give specific answers without a lot more specific information.

 --
 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




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


[Tutor] function help

2011-02-07 Thread Ashley F
ok...here's the function I've written so far.
 
def padWithGaps(seq):
    for letter in seq:
   letter=-
   line=len(seq)
   dashline=line*letter
    return dashline
 
def replace(someString,position,letter):
    first=someString[0:position]
    second=letter
    third=someString[position+1:len(someString)]
    newString=first+second+third
    return newString
 
##findScore(MPFVS,MS-V-) would return a score of 2
def findScore(first,second):
    count=0
    for position in range(0,len(first)):
 if first[position]==second[position]:
 count=count+1
 position=position+1
    return count
 
#shorter is a 3 amino acid sequence
##longer is any length sequence greater than 3
###i=first amino acid; j=second amino acid; k=third amino acid
def findAlignment(shorter,longer):
 for i in range(0,len(longer)-2):
 for j in range(1,len(longer)-1):
  for k in range(2,len(longer)):
   dashline=padWithGaps(longer)
   nextLine=replace(dashline,i,shorter[0])
   nextNext=replace(nextLine,j,shorter[1])
   alignment=replace(nextNext,k,shorter[2])
   score=findScore(longer,alignment)
   don't know what to do here
  print longer
  print alignment
  print Score =  + str(score)
 
I don't know what to do at the end of my loop but what I'm trying to do in 
pseudocode is:
 if that alignment has the best score seen so far
  save the score and the alignment
print the best score and the best alignment


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


Re: [Tutor] nested loops

2011-02-07 Thread Michael M Mason

Alan Gauld wrote:-
 Wayne Werner waynejwer...@gmail.com wrote 
 found = False
  highscore = 0
  alignment = somealignment
  for x in something and not found:
  for y in somethingelse and not found:
for z in evenmoresomething:
if x+y+z  highscore:
highscore = x+y+z
alignment = newalignment
 found = True
 break

 HTH,

That's going to exit first time through, isn't it?

-- 
Michael


This mail was sent via Mail-SeCure System.



 
 

This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals  computer 
viruses.




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


Re: [Tutor] function help

2011-02-07 Thread James Reynolds
I'm not sure of the answer to your question, because i'm not sure I
understand it. Perhaps you could rephrase it?

But, there is some other stuff I noticed though:

def padWithGaps(seq):

for letter in seq:

   letter=-

   line=len(seq)

   dashline=line*letter

return dashline



This function is fairly inefficient. Let's say you pass the function a
sequence three items long something like a_list = ['a','b','c']. Your
telling Python to create a dashed line three dashes long
three separate times. So, you do it for the 'a' part of the sequence, the
'b' and the 'c'. You can condense this to something like:

def padWithGaps(seq):

lent = len(seq)

return lent*'-'


And you really don't need to have a separate function for that, as you can
just do it on the fly

Another thing, whenever your taking a slice of a list and the first argument
is 0, you can just omit that. For example, from my list a_list example above
a_list[0:2] is equivalent to a_list[:2]

As for the rest of them, what you could do is pass each function data that
you would expect to be passed under normal operation (assuming this is
possible of course) and instead of using return use print instead and see if
the results are what you expect.

What I mean is, let's say I pass the results from the padWithGaps (the
results of which I call dashline to be consistent) to the next function:

def replace(someString,position,letter):

first=someString[0:position]

second=letter

third=someString[position+1:len(someString)]

newString=first+second+third

return newString


So, I can do something like z = replace(dashline,0,'a') and then print z.
What the results should be is a--.


def findScore(first,second):

count=0

for position in range(0,len(first)):

 if first[position]==second[position]:

 count=count+1

 position=position+1

return count


With this function here, there is a few things you can do to optimize and
clean up clutter as well. I only point this out because it pays huge
dividends in the long run (or it has for me at least). The first thing
though is that you don't need to have the line position=position+1. Python
will go to the next item in the list position whether you tell it to or
not. So below is the same thing but without the position +=1 line:



def findScore(first,second):

count=0

for position in range(0,len(first)):

 if first[position]==second[position]:

 count=count+1

return count


The other thing I would suggest is to use enumerate. Enumerate is your
friend. And the last thing I would suggest is whenever you want to do
something like a = a+1, you can just do a +=1.


 def findScore2(first,second):

count=0

for i, position in enumerate(first):

 if position==second[i]:

 count+=1

return count


enumerate returns both the next item in the list and the position of that
item in the list (in this case, I called that variable i). So you will find
that if you run findScore2 you will have the same results as findScore. Or
at least you should ;)

On Mon, Feb 7, 2011 at 11:45 AM, Ashley F aflint...@yahoo.com wrote:

 ok...here's the function I've written so far.

 def padWithGaps(seq):
 for letter in seq:
letter=-
line=len(seq)
dashline=line*letter
 return dashline

 def replace(someString,position,letter):
 first=someString[0:position]
 second=letter
 third=someString[position+1:len(someString)]
 newString=first+second+third
 return newString

 ##findScore(MPFVS,MS-V-) would return a score of 2
 def findScore(first,second):
 count=0
 for position in range(0,len(first)):
  if first[position]==second[position]:
  count=count+1
  position=position+1
 return count

 #shorter is a 3 amino acid sequence
 ##longer is any length sequence greater than 3
 ###i=first amino acid; j=second amino acid; k=third amino acid
 def findAlignment(shorter,longer):
  for i in range(0,len(longer)-2):
  for j in range(1,len(longer)-1):
   for k in range(2,len(longer)):
dashline=padWithGaps(longer)
nextLine=replace(dashline,i,shorter[0])
nextNext=replace(nextLine,j,shorter[1])
alignment=replace(nextNext,k,shorter[2])
score=findScore(longer,alignment)
don't know what to do here
   print longer
   print alignment
   print Score =  + str(score)

 I don't know what to do at the end of my loop but what I'm trying to do in
 pseudocode is:
  if that alignment has the best score seen so far
   save the score and the alignment
 print the best score and the best alignment


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



[Tutor] JES Jython

2011-02-07 Thread Eun Koo
Hi I have a problem in JES getting a solution to a function. Is there a way you 
guys can help?


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


Re: [Tutor] JES Jython

2011-02-07 Thread bob gailer

On 2/7/2011 2:45 PM, Eun Koo wrote:
Hi I have a problem in JES getting a solution to a function. Is there 
a way you guys can help?




Maybe.

You might say more about the problem.

What is JES and how does it relate to Python?

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

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


Re: [Tutor] JES Jython

2011-02-07 Thread Stefan Behnel

Eun Koo, 07.02.2011 20:45:

Hi I have a problem in JES getting a solution to a function. Is there a way you 
guys can help?


If you can provide enough information for us to understand what your 
problem is, we may be able to help you. It's a matter of politeness to help 
us help you. The more work we have to put into figuring out what you want 
(or even what your words are supposed to mean), the less likely it is that 
someone will do that and help you out.


Stefan

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


Re: [Tutor] nested loops

2011-02-07 Thread Steven D'Aprano

Alan Gauld wrote:


Wayne Werner waynejwer...@gmail.com wrote
You probably want to add a sentinel to break out of the outer
loops too:


I don't think you want to break out of *any* of the loops. Otherwise you 
will skip testing combinations. In your example, the first time you set 
highscore and alignment, you break out of all three loops and only test 
the first triple x,y,z.



  found = False

highscore = 0
alignment = somealignment
for x in something and not found:
 for y in somethingelse and not found:
  for z in evenmoresomething:
  if x+y+z  highscore:
  highscore = x+y+z
  alignment = newalignment

found = True
break


That's the equivalent of a return in the innermost loop. If you're 
looking for the *first* matching highscore, that's fine, but not if you 
want the biggest.



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


Re: [Tutor] JES Jython

2011-02-07 Thread Steven D'Aprano

Eun Koo wrote:

Hi I have a problem in JES getting a solution to a function. Is there a way you 
guys can help?


Probably not. This is a mailing list about learning the language Python, 
not specific to JES (whatever that is!) under Jython. If JES has a 
support forum dedicated to it, you should try there. Otherwise, try a 
Jython mailing list. You might try the main Python mailing list, 
python-l...@python.org, also available on Usenet as comp.lang.python.



--
Steven


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


Re: [Tutor] function help

2011-02-07 Thread Steven D'Aprano

Ashley F wrote:

ok...here's the function I've written so far.
 
def padWithGaps(seq):

for letter in seq:
   letter=-
   line=len(seq)
   dashline=line*letter
return dashline



I don't think that's a useful function. It seems to do a HUGE amount of 
work that just keeps getting thrown away. Let's say seq = GACT, this 
function will do the following:


letter = G
letter = -
line = 4  # len of seq
dashline = 
letter = A
letter = -
line = 4
dashline = 
letter = C
letter = -
line = 4
dashline = 
letter = T
letter = -
line = 4
dashline = 

It does everything four times. Now imagine that seq is a million 
characters long instead of four! This will do the job *much* faster:


def padWithGaps(seq):
return - * len(seq)


*Much* faster, much easier to read.

[...]

I don't know what to do at the end of my loop but what I'm trying to do in 
pseudocode is:
 if that alignment has the best score seen so far
  save the score and the alignment
print the best score and the best alignment


You need to store the current best score and the current best alignment. 
Then each time around the innermost loop, you need to calculate the 
score and alignment (as you already do), and compare them to the best 
seen so far. If they are worse or equal, you don't need to do anything, 
just go on to the next loop as normal. But if they are better, then you 
need to update the best score and alignment, and print them.


if score  best_score:
best_score = score
best_alignment = alignment
print 'best seen so far is', score, alignment

Does that help? Try writing the code, and if you still can't get it 
working, ask again.




--
Steven

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


Re: [Tutor] nested loops

2011-02-07 Thread Alan Gauld


Steven D'Aprano st...@pearwood.info wrote

I don't think you want to break out of *any* of the loops. Otherwise 
you will skip testing combinations.


In that case I misread the OP. I thought he specifically wanted
to avoid testing all the options and exit when he reached his target.

In your example, the first time you set highscore and alignment, you 
break out of all three loops


Yep, thats what I thought was being asked for.
It seems I mistook the intent. reading too quickly I suspect.

Alan G 



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


Re: [Tutor] Converting From Unicode to ASCII!!

2011-02-07 Thread David Hutto
On Mon, Feb 7, 2011 at 10:15 PM, Nevins Duret dur...@bellsouth.net wrote:
 Hello all,



     Don’t know if I’ll be bashed on this forum for doing this,
 but I will assure you I have the best intentions and

 simply want to apply a real world problem and how to go about solving it
 using python3.1.  Here is my  predicament.

 A good friend of mine locked herself out of her computer and forgot her
 password.  I pretty much scoured the internet as

 a resource only to hit a brick wall.  I tried using ophcrack version 2.3.1
 in order to obtain the password and felt completely at home

 being that it was Linux,  but then towards the end it failed and the output
 of this file which seems to contain the Users and passwords

The linux forums might be better. Or you could use:

http://www.google.com/search?client=ubuntuchannel=fsq=linux+lost+password+brute+forceie=utf-8oe=utf-8


 but in Unicode format:



 Administrator:500::31d6cfe0d16ae931b73c59d7e0c089c 0:::
 Guest:501::31d6cfe0d16ae931b73c59d7e0c089c0:::
 SUPPORT_388945a0:1002::881037e0b6909b04b6900f7c806 dca6e:::
 HelpAssistant:1004:b209ce7e3ff7aea1131906e9f5df481
 9:d83f663c50bcd5815ccb94f9e38a9a4b:::
 Beverly:1005:6395b1acd69aaad3b435b51404ee:992a
 c78ffb08204c592c6e47b916f85d:::



 And it didn’t complete as a result of this error message:



 Tables found:
 /mnt/hdc/tables/xp_free_small

 Found one partition that contains hashes:
 /mnt/hda1/WINDOWS/system32/config

 Starting Ophcrack
 QIconvCodec::convertFromUnicode: using ASCII for conversion, iconv_open
 failed
 QIconvCodec::convertToUnicode: using ASCII for conversion, iconv_open failed
 /home/tux/launch.sh: line 100: 1044 Killed
 ABLES_INLINE -w $FOUND/ -n $numcpu -o /tmp/ophcrack.txt $opts
 Press a key to exit::



 Now , I remember reading somewhere that Python is very good for converting
 Unicode

 data into ASCII and admittedly know nothing about this:



 Is there a work around in Python where I can simply import the file like and
 convert it to readable string using

 A for loop.



 Any help on this would be greatly appreciated.  So far, I’m reading up on
 this topic at this url:

 http://docs.python.org/howto/unicode.html



 Best Regards,



 Nevins Duret



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





-- 
The lawyer in me says argue...even if you're wrong. The scientist in
me... says shut up, listen, and then argue. But the lawyer won on
appeal, so now I have to argue due to a court order.

Furthermore, if you could be a scientific celebrity, would you want
einstein sitting around with you on saturday morning, while you're
sitting in your undies, watching Underdog?...Or better yet, would
Einstein want you to violate his Underdog time?

Can you imagine Einstein sitting around in his underware? Thinking
about the relativity between his pubic nardsac, and his Fruit of the
Looms, while knocking a few Dorito's crumbs off his inner brilliant
white thighs, and hailing E = mc**2, and licking the orangy,
delicious, Doritoey crust that layered his genetically rippled
fingertips?

But then again, J. Edgar Hoover would want his pantyhose intertwined
within the equation.

However, I digress, momentarily.

But Einstein gave freely, for humanity, not for gain, other than
personal freedom.

An equation that benefited all, and yet gain is a personal product.

Also, if you can answer it, is gravity anymore than interplanetary static cling?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting From Unicode to ASCII!!

2011-02-07 Thread David Hutto
And I forgot, that you don't have to install another version, but just
boot from the live disk, and mount the partition. But from looking,
you should be able to recover with linux utilities. Look here:

http://aplawrence.com/Linux/lostlinuxpassword.htmlhttp://aplawrence.com/Linux/lostlinuxpassword.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor