Re: [Tutor] second if

2014-02-10 Thread David Palao
Also, could you explain better what is your doubt? You don't
understand what index = 1 means, or why this if at this point, or
anything else?

Best

2014-02-07 17:14 GMT+01:00 rahmad akbar matbioi...@gmail.com:
 he guys, i am trying to understand this code: i understand the first if
 statement (if line.startswith..) in read_fasta function but couldnt
 understand the next one(if index =...). thanks in advance!!

 import sys
 #class declaration with both attributes we need
 class Fasta:
 def __init__(self, name, sequence):
 #this will store the sequence name
 self.name = name
 #this  will store the sequence itself
 self.sequence = sequence

 #this function will receive the list with the file
 #contents, create instances of the Fasta class as
 #it scans the list, putting the sequence name on the
 #first attribute and the sequence itself on the second
 #attribute
 def read_fasta(file):
 #we declare an empty list that will store all
 #Fasta class instances generated
 items = []
 index = 0
 for line in file:
 #we check to see if the line starts with a  sign
 if line.startswith():
#if so and our counter is large than 1
#we add the created class instance to our list
#a counter larger than 1 means we are reading
#from sequences 2 and above
if index = 1:
items.append(aninstance)
index+=1
#we add the line contents to a string
name = line[:-1]
#and initialize the string to store the sequence
seq = ''
#this creates a class instance and we add the attributes
#which are the strings name and seq
aninstance = Fasta(name, seq)
 else:
#the line does not start with  so it has to be
#a sequence line, so we increment the string and
#add it to the created instance
 seq += line[:-1]
 aninstance = Fasta(name, seq)

 #the loop before reads everything but the penultimate
 #sequence is added at the end, so we need to add it
 #after the loop ends
 items.append(aninstance)
 #a list with all read sequences is returned
 return items

 fastafile = open(sys.argv[1], 'r').readlines()
 mysequences = read_fasta(fastafile)

 print mysequences

 for i in mysequences:
 print i.name

 --
 many thanks
 mat

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

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


Re: [Tutor] second if

2014-02-10 Thread Alan Gauld

On 07/02/14 16:14, rahmad akbar wrote:

he guys, i am trying to understand this code: i understand the first if
statement (if line.startswith..) in read_fasta function but couldnt
understand the next one(if index =...). thanks in advance!!


I'm not sure what you don't understand about it.
But so far as I can see its effect is to miss out
the first line in the file that starts with ''

The logic appears to be, in pseudo code:

read the file line buy line
 if line starts with 
 if not the first time add instance to the collection
 add one to index
 create an instance.

It has to miss the first one because an instance doesn't
exist yet. It seems odd and I'd probably have done it this
way:

read the file line buy line
 if line starts with 
create an instance.
add instance to the collection

But there may be reasons why the author didn't do that.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

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


Re: [Tutor] second if

2014-02-10 Thread David Palao
I guess the replies by Alan and Peter precisely answer to your question?

Best

2014-02-10 12:46 GMT+01:00 rahmad akbar matbioi...@gmail.com:
 David,

 thanks for your reply. i cant figure out why the if at that point and what
 is the 'if' try to accompolish


 On Mon, Feb 10, 2014 at 11:52 AM, David Palao dpalao.pyt...@gmail.com
 wrote:

 Also, could you explain better what is your doubt? You don't
 understand what index = 1 means, or why this if at this point, or
 anything else?

 Best

 2014-02-07 17:14 GMT+01:00 rahmad akbar matbioi...@gmail.com:
  he guys, i am trying to understand this code: i understand the first if
  statement (if line.startswith..) in read_fasta function but couldnt
  understand the next one(if index =...). thanks in advance!!
 
  import sys
  #class declaration with both attributes we need
  class Fasta:
  def __init__(self, name, sequence):
  #this will store the sequence name
  self.name = name
  #this  will store the sequence itself
  self.sequence = sequence
 
  #this function will receive the list with the file
  #contents, create instances of the Fasta class as
  #it scans the list, putting the sequence name on the
  #first attribute and the sequence itself on the second
  #attribute
  def read_fasta(file):
  #we declare an empty list that will store all
  #Fasta class instances generated
  items = []
  index = 0
  for line in file:
  #we check to see if the line starts with a  sign
  if line.startswith():
 #if so and our counter is large than 1
 #we add the created class instance to our list
 #a counter larger than 1 means we are reading
 #from sequences 2 and above
 if index = 1:
 items.append(aninstance)
 index+=1
 #we add the line contents to a string
 name = line[:-1]
 #and initialize the string to store the sequence
 seq = ''
 #this creates a class instance and we add the attributes
 #which are the strings name and seq
 aninstance = Fasta(name, seq)
  else:
 #the line does not start with  so it has to be
 #a sequence line, so we increment the string and
 #add it to the created instance
  seq += line[:-1]
  aninstance = Fasta(name, seq)
 
  #the loop before reads everything but the penultimate
  #sequence is added at the end, so we need to add it
  #after the loop ends
  items.append(aninstance)
  #a list with all read sequences is returned
  return items
 
  fastafile = open(sys.argv[1], 'r').readlines()
  mysequences = read_fasta(fastafile)
 
  print mysequences
 
  for i in mysequences:
  print i.name
 
  --
  many thanks
  mat
 
  ___
  Tutor maillist  -  Tutor@python.org
  To unsubscribe or change subscription options:
  https://mail.python.org/mailman/listinfo/tutor
 




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


Re: [Tutor] second if

2014-02-10 Thread Danny Yoo
By the way, if you are trying to write your own FASTA parser, please reconsider.

A good FASTA parser has been written by the folks at BioPython.org.
Use that one unless you really know what you're doing.

See:

http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec12

for example usage.  If you are using your own home-grown FASTA parser,
consider switching to the biopython one.


(As Lincoln Stein of Bioperl fame has observed, reimplementing a FASTA
parser should not be a rite of passage.  Reference: the talk
Bioinformatics: Building a Nation from a Land of City States,
mentioned in  http://www.oreillynet.com/pub/a/network/2002/01/29/bioday2.html.
 Sadly, the audio to his keynote speech does not appear to be on Dr.
Dobbs Technetcast anymore, as that web site appears to have fallen on
hard times.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] second if

2014-02-09 Thread Dave Angel
 rahmad akbar matbioi...@gmail.com Wrote in message:

Between invisible colors and a tiny font, your message is totally
 incomprehensible to me. This is a text list, please post in text,
 not html.

-- 
DaveA

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


[Tutor] Second follow up

2013-02-26 Thread Jack Little
How would I go from one def statement to another? I am developing a text based 
rpg.

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


Re: [Tutor] Second follow up

2013-02-26 Thread Dave Angel

On 02/26/2013 09:23 AM, Jack Little wrote:

How would I go from one def statement to another? I am developing a text based 
rpg.

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




For your next thread, please try to pick a subject line that has 
something to do with what you're asking, or what you're trying to learn 
about.


A def statement defines a function (or method).  Once it's defined, the 
compiler goes on to the next line, and if that's a def statement, it 
defines that function.


So all you need is a text editor.  Just understand that code that will 
call those functions from the top-level needs to be *after* the 
definition is complete.  Code that calls functions from inside a 
function does not need to be in any particular order.


If this isn't what you want, then try composing a ten-line sample, tell 
us what environment you're running it in, and what you hoped for, and 
what it did instead.



On the other hand, perhaps you're asking how to make indirect calls to 
functions.  A function object can be stored in a 'variable', simply by 
assigning it without using parentheses.  You can then later call that 
function by naming the object, and following the object with the 
parentheses.  Simple example follows;


def func1(name):
print function1, running with, name

def func2(name):
print function2, running with, name

funclist = []
funclist.append(func1)
funclist.append(func2)
funclist.append(func1)

funclist[1](Sam)
will call func2, and pass it Sam as an argument.

Normally, if you're doing this type of thing, you'd be using methods, 
not functions, but I'm not going to introduce classes unless you're 
already familiar with them.


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


Re: [Tutor] Second follow up

2013-02-26 Thread Alan Gauld

On 26/02/13 14:23, Jack Little wrote:

How would I go from one def statement to another?


Type it in.

Based on your message that's all I can suggest.
Can you explain what you mean?

What do you have in mind by a def statement?

def foo():
   print 'foo'

def bar():
   print 'bar'

Those are two def statements. You can add as many
more as you like? But I suspect that's not really
what you mean?


I am developing a text based rpg.


I don't see whether/how that makes any difference to anything.

Telling us which OS and Python version you are using and what 
programming tools might help though.


--
Alan G
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] Second follow up

2013-02-26 Thread Mark Lawrence

On 26/02/2013 14:23, Jack Little wrote:

How would I go from one def statement to another? I am developing a text based 
rpg.

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



I'd like to see your project when it's finished as a text based rocket 
propelled grenade seems very interesting, or are we talking cross 
purposes owing to a major lack of data?


--
Cheers.

Mark Lawrence

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


Re: [Tutor] Second follow up

2013-02-26 Thread Steven D'Aprano

On 27/02/13 01:23, Jack Little wrote:

How would I go from one def statement to another? I am developing a text based 
rpg.



def first_function():
# write your code here, indented by FOUR spaces or ONE tab


def second_function():  # NO INDENT
# write your code here, indented by FOUR spaces or ONE tab


Does that help?


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


Re: [Tutor] Second follow up

2013-02-26 Thread Steven D'Aprano

On 27/02/13 02:12, Mark Lawrence wrote:

On 26/02/2013 14:23, Jack Little wrote:

How would I go from one def statement to another? I am developing a text based 
rpg.


I'd like to see your project when it's finished as a text based rocket 
propelled grenade seems very interesting, or are we talking cross purposes 
owing to a major lack of data?



RPG: Role Playing Game.



--
Steven



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


Re: [Tutor] Second follow up

2013-02-26 Thread Mark Lawrence

On 26/02/2013 16:01, Steven D'Aprano wrote:

On 27/02/13 01:23, Jack Little wrote:

How would I go from one def statement to another? I am developing a
text based rpg.



def first_function():
 # write your code here, indented by FOUR spaces or ONE tab


def second_function():  # NO INDENT
 # write your code here, indented by FOUR spaces or ONE tab


Does that help?




Get thee behind me Satan/Steven, tabs indeed :)

--
Cheers.

Mark Lawrence

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


[Tutor] Second attempt convert DateTimeTyep to datetime.datetime

2006-11-10 Thread johnf
Hi,

I'm using FreeTDS (MS SQL database access lib) and for datetime fields it 
returns a type 'DateTimeType'.  I need it in type 'datetime.datetime'.  There 
is very little in the form of a tutorial that explains what I need to do.  

Can someone help me with this issue.

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


Re: [Tutor] Second attempt convert DateTimeTyep to datetime.datetime

2006-11-10 Thread Luke Paireepinart
johnf wrote:
 Hi,

 I'm using FreeTDS (MS SQL database access lib) and for datetime fields it 
 returns a type 'DateTimeType'.  I need it in type 'datetime.datetime'.  There 
 is very little in the form of a tutorial that explains what I need to do.  
   
if a datetimetype object has a __str__ or __repr__ method,
you can probably just use datetime.datetime's parsing system to convert 
it from a string into a datetime.datetime object.
 Can someone help me with this issue.

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

   

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