Re: [Tutor] triple-nested for loop not working

2011-05-05 Thread Andre Engels
I have not checked the rest of your code, but:

 for line in seqalign:
     for i in len(finalmotif_seqs):      # for item in finalmotif_seqs:
         for i in len(finalmotif_annot):     # for item in finalmotif_annot:

I see two problems here:
1. You are using the same loop variable in both loops here. That's
likely to cause problems
2. You let the loops go over len(finalmotif_seqs).
len(finalmotif_seqs) is a number, and you can't loop over a number.
You should use the form as you write after the #.

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] assigning a variable a value

2011-05-05 Thread Kyle Benak
Hi,

I am learning python and I am trying to write a simple guess the number 
game. I wrote the program in the IDLE, and I set the variable tries=1 to keep 
up 
with the number of tries it takes to guess the number, but when I try to run 
the 
program it gives the error message improper syntax and highlights the word 
tries.  So, I assigned the variable tries the value 1 in the python shell 
window 
and it works fine there.  Can you tell me why it won't work in the program? A 
copy of my code is below for clarification.

#Guess My Number
#
#The computer picks a random number between 1 and 100
#The player tries to guess it and the computer lets
#the player know if the guess is too high, too low, or correct
import random
print('Welcome to Guess My Number!')
print('\nI\'m thinking of a number between 1 and 100.')
print('Try and guess the number in as few turns as possible.')

#set initial values
num = random.randint(1,100)
guess = int(input('Take a guess: ')
tries = 1
while guess != num:
    if guess  num:
  print('Too high. Guess lower.')
    else:
  print('Too low. Guess higher.')
    guess=input('Take another guess: ')
    tries += 1
print('You guessed it. The number was',num)
print('Congratulations, You guessed the correct answer.'
print('It only took you',tries,'tries.')
  
input('\n\nPress enter to exit.')



I highlighted the problem in red.  

Thanks for any help.
Kyle___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning a variable a value

2011-05-05 Thread Andre Engels
On Thu, May 5, 2011 at 2:19 AM, Kyle Benak kbena...@yahoo.com wrote:

 I am learning python and I am trying to write a simple guess the number
 game. I wrote the program in the IDLE, and I set the variable tries=1 to
 keep up with the number of tries it takes to guess the number, but when I
 try to run the program it gives the error message improper syntax and
 highlights the word tries.  So, I assigned the variable tries the value 1 in
 the python shell window and it works fine there.  Can you tell me why it
 won't work in the program? A copy of my code is below for clarification.

If the parser tells you there's a syntax error, it is often in the
line it shows, but also often in the line preceding that. In this
case, it is the latter: You have two opening brackets there, but only
one closing bracket.

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning a variable a value

2011-05-05 Thread Alan Gauld


Kyle Benak kbena...@yahoo.com wrote

I am learning python and I am trying to write a simple guess the 
number
game. I wrote the program in the IDLE, and I set the variable 
tries=1 to keep up
with the number of tries it takes to guess the number, but when I 
try to run the
program it gives the error message improper syntax and highlights 
the word

tries.


First please post the actual error in full, not just a rough summary.
Pythopn error messages are very informative and helpful once
you know how to read them. However, in this case its not needed.

The thing to remember with errors, especially syntax errors,  is that
Python reports them where it identifies the problem. But that may
be a line or so later than where the actual error occurs. That is
what happened here. Look at the guess= line and count the
parentheses


num = random.randint(1,100)
guess = int(input('Take a guess: ')
tries = 1


print('Too low. Guess higher.')
guess=input('Take another guess: ')


you probably need to convert to int() here too...

HTH,

--
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] Titles from a web page

2011-05-05 Thread Alan Gauld


louis leichtnam l.leicht...@gmail.com wrote

I'm trying to write a program that looks in a webpage in find the 
titles of

a subsection of the page:

Can you help me out? I tried using regular expression but I keep 
hitting

walls and I don't know what to do...


Regular expressions are the wrong tool for parsing HTML unless
you are searching for something very simple.

There is an html parser in the Python standard library (*) that you
can use if the HTML is reasonably well formed. If its sloppy you
would be better with something like BeautifulSoup or lxml.

If the page is written in XHTML then you could also use the
element tree module which is designed for XML parsing.

(*)In fact there are two! - htmllib and HTMLParser. The former is more
powerful but more complex. Some brief examples can be found
in my tutor here:

http://www.alan-g.me.uk/tutor/tutwebc.htm

Note, the topic is not complete, the last few sections are
placeholders only...

HTH,

Alan G. 



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


Re: [Tutor] Need help with arrays

2011-05-05 Thread Matt Gregory

On 5/4/2011 10:30 AM, Patrick P. wrote:

Hello,

I hope this is the right way to ask my question, if not, sorry to bother
you. Maybe you can tell me who to ask.
Ok so here is my code

[snip]

A = np.array([[m111,m121], [m211,m221]])
B = np.array([[m112,m122], [m212,m222]])
print(np.dot(A,B))

Traceback (most recent call last):
File C:/Python26/helpfiletest.py, line 36, in module
print(np.dot(A,B))
ValueError: objects are not aligned
-
I get it why theres and error message, because it's trying to multiply a
2x2x100 array with another 2x2x100 array and doesn't know how to do that.
What I actually want is 100 2x2 arrays and then mutliply them individually.
Can anyone help me with that?


As Alan said, you'll likely get good help on the numpy listserv, but I 
think this might be what you want, although I'm not sure it's the 
tersest way to express it:


# Swap axes twice on A and B to make them (100, 2, 2)
A_new = np.swapaxes(np.swapaxes(A, 0, 2), 1, 2)
B_new = np.swapaxes(np.swapaxes(B, 0, 2), 1, 2)

# Multiply the 2x2 arrays together using list comprehension
C = np.array([np.dot(a, b) for a, b in zip(A_new, B_new)])
print C

I'm certain there is a more clever way (ie. some function within numpy) 
to do that last part.


matt

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


Re: [Tutor] Reading elements in a file

2011-05-05 Thread bob gailer

On 5/4/2011 6:59 PM, Alan Gauld wrote:


The string methods are builtin and the string
module is really only needed for backwatds
compatibility these days.


Yes, except for:

8.1.5. String functions
The following functions are available to operate on string and Unicode 
objects. They are not available as string methods.


string.capwords(s[, sep])

string.maketrans(from, to)


--
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] Reading elements in a file

2011-05-05 Thread Prasad, Ramit
 string.capwords(s[, sep])
So capwords is a little bit different but you can use a combination of split() 
and title() to do some of it. Title() will work for the default case, but if 
you split on non-whitespace then you will need to manually use split().
'test test test'.title()
'Test Test Test'

This is the only one I think you cannot do from the str object. (Well, not in 
Python2. Python3 has maketrans built into the str object.).
string.maketrans(from, to)


Ramit



Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase  Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase 
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] dictionary

2011-05-05 Thread louis leichtnam
HEllo everyone,

I have a dictionnary, and I would like to print only the values that have
more/equal than 3 spaces in them for example: My name is Xavier.

Can you help me out,

Thanks

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


Re: [Tutor] dictionary

2011-05-05 Thread naheed arafat
Supposing your dictionary like this: dict={1:'My name is X',2:'My name is x
y z',3: 'i am X'}
You can use len(list) :
 dict={1:'My name is X',2:'My name is x y z',3: 'i am X'}
 for values in dict.values():
...  if len(values.split(' '))3:
...print values
My name is X
My name is x y z

On Fri, May 6, 2011 at 7:56 AM, louis leichtnam l.leicht...@gmail.comwrote:

 HEllo everyone,

 I have a dictionnary, and I would like to print only the values that have
 more/equal than 3 spaces in them for example: My name is Xavier.

 Can you help me out,

 Thanks

 Louis

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


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


Re: [Tutor] dictionary

2011-05-05 Thread Steven D'Aprano

louis leichtnam wrote:

HEllo everyone,

I have a dictionnary, and I would like to print only the values that have
more/equal than 3 spaces in them for example: My name is Xavier.



d = {1: Hello world, 2: My name is Xavier, 3: ham and eggs,
 4: Eat more cheese please!, 5: spam spam spam spam spam spam,
 6: how much wood would a woodchuck chuck if a woodchuck would
  chuck wood?, 7: nice cup of tea and a slice of cake}
for value in d.values():
if value.count( ) = 3:
print(value)



--
Steven

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