Re: [Tutor] Re: A simpler mousetrap

2004-12-19 Thread Alan Gauld
Rats, a premature posting sorry.

> > Also, just as interesting, yet probably less reliable:
> >
> > a = list(a)
> > a[-3:] = 'bak'
> > a = "".join(a)
>
>
> The problem with all of these versions is they assume the
> extension will be three characters long. In DOS it could be *up to*
> three characters, but in Windows post 95 the extension can be
longer,
> eg .html is often seen. And on non Windows platforms loing
extensions
> are common.

> > > x=os.path.splitext(a)[0]+'.bak'

Whereas this technique handles the different size extensions safely.

Alan G.

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re: A simpler mousetrap

2004-12-19 Thread Alan Gauld

> Also, just as interesting, yet probably less reliable:
>
> a = list(a)
> a[-3:] = 'bak'
> a = "".join(a)
>


The problem with all of these versions is they assume the
extension will be three characters long. In DOS it could be *up to*
three characters, but in Windows post 95 the extension can be longer,
eg .html is often seen. And on non Windows platforms loing extensions
are common.

> OR
>
> a = a.rstrip('pct')
> a = a+'bak'
>
> OR
>
> a = a.rstrip('pct')+'bak'  ## Which is essentially the same thing
>
> OR
>
> a = a[:-3]+'bak'
>
> ETC.
>
> HTH,
> Jacob
>
> > x=os.path.splitext(a)[0]+'.bak'
> >
> > Ah, jolly good, looks a bit simpler. Thanks!
> >
> > Regards,
> >
> > Liam Clarke
> >
> > On Thu, 16 Dec 2004 09:44:03 +0100, Wolfram Kraus
> > <[EMAIL PROTECTED]> wrote:
> > > Liam Clarke wrote:
> > > > Hi all,
> > > >
> > > > I'm writing some code, and I want to take a given path +
filename, and
> > > > change the file extension to *.bak.
> > > >
> > > > In doing so, (entirely internal this function), I am
assuming -
> > > >
> > > > That the file will always have an extension
> > > > Thathe extension will vary
> > > > But, it will follow the general DOS format of name.ext
> > > >
> > > > So, I came up with this -
> > > >
> > > > a="./tc/arc/gab.pct"
> > > >
> > > > x=a.replace(a[a.rfind('.'):len(a)],'.bak')
> > > >
> > > > x="./tc/arc/gab.bak"
> > > >
> > > > So, it works, but it feels a bit, well, hacky to me. Not
nearly hacky
> > > > as using an regex though ; )
> > > >
> > > > I thought about
> > > >
> > > > a="./tc/arc/gab.pct"
> > > >
> > > > aList=a.split('.')
> > > > aList[-1]='bak'
> > > > a=".".join(aList)
> > > >
> > > > but I'm wondering if there's a simpler way, as there usually
seems to
> > > > be, and it's always so obvious once I'm shown it, like 6
down - Six on
> > > > vehicle live in the manse (VI + car). Obvious once you know.
> > > >
> > > > Regards,
> > > >
> > > > Liam Clarke
> > >
> > > Hey Liam!
> > >
> > > The os.path module is your friend, especially split and
splitext:
> > > http://docs.python.org/lib/module-os.path.html
> > >
> > > HTH,
> > > Wolfram
> > >
> > > ___
> > > Tutor maillist  -  [EMAIL PROTECTED]
> > > http://mail.python.org/mailman/listinfo/tutor
> > >
> >
> >
> > -- 
> > 'There is only one basic human right, and that is to do as you
damn well
> please.
> > And with it comes the only basic human duty, to take the
consequences.
> > ___
> > Tutor maillist  -  [EMAIL PROTECTED]
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] OT: Flow chart

2004-12-19 Thread Eri Mendz
Hello All,

I'm looking for any good link or tutorial of flow charting i can use related for
programming. Maybe having symbols and similar stuffs. This may sound 
old-fashion or antiquated to you but i feel this may help me with the logic and 
flow
controls when i do code in python.

Anyone pointing me to the right direction is appreciated.

--
regards,
erimendz
--
regards,
eri mendz
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: OT: Flow chart

2004-12-19 Thread Jorge Luiz Godoy Filho
Eri Mendz, Domingo 19 Dezembro 2004 08:35, wrote:

> Hello All,
> 
> I'm looking for any good link or tutorial of flow charting i can use
> related for programming. Maybe having symbols and similar stuffs. This may
> sound old-fashion or antiquated to you but i feel this may help me with
> the logic and flow controls when i do code in python.
> 
> Anyone pointing me to the right direction is appreciated.

Take a look at UML.  It has several diagrams that help a lot and, depending
on the tool you're using, you can even generate the skeleton of the code
from the diagrams.

If you're on a *nix platform, take a look at Umbrello.


Be seeing you,
Godoy.

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problems with class, no output

2004-12-19 Thread Dave S
Hello again  :-) ,
This script is very much a work in progress, and I think only the second 
time I have tried classes. What I expected it to do was to at least 
print 'hi there' so I know its alive, then dump some status info to my 
log program. It does zip, executes OK but no output.

I just know you guys are going to tell me I have missed a () or . somewhere
Any help gratefully appreciated
Dave


#!/usr/bin/env python
# -*- coding: iso8859_1 -*-
"""
arch_data.py 1.0 This is the read archive data script
"""
from os import listdir
from cPickle import load
from logger import log
from config import data_dir
debug=True
   
class Arch_data:
   
   def __init__(self):
   
   self.file_names=listdir(data_dir)
   self.file_names.sort()
   self.file_name_ptr=0
   
   def read_next():
   """
   when executed reads next data file from data_dir extracts date,
   time,julian day,sequence count & flag from the file name.
   
   Also adds last_file flag and contents of file to the list of 
returned
   parameters
   """
   print 'hi there'
   
   file_name=self.file_names[self.file_name_ptr]
   
   # Ignore the archive_read.py utility script in the data dir
##if file_name=='archive_read.py':
##if debug:
##log('II','arch_data','Ignoring "archive_read.py"')
##self.file_name_ptr+=1
##read.next()
##return
   
   # Extract info from the encoded filename :-)
   file_yy=file_name[:4]
   file_mm=file_name[4:6]
   file_dd=file_name[6:8]
   file_HH=file_name[9:11]
   file_MM=file_name[11:13]
   file_jj=file_name[14:17]
   file_seq=file_name[18:21]
   file_flag=file_name[22:24]
   
   if debug:
   log('II','arch_data','unpickling '+file_name)
   
   pickle_file=open(data_dir+file_name,'r')
   file=load(pickle_file)
   pickle_file.close()
   
   print 
file_yy,file_mm,file_dd,file_HH,file_MM,file_jj,file_seq,file_flag

   self.file_name_ptr+=1
   
arch_data=Arch_data()
arch_data.read_next

  
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems with class, no output

2004-12-19 Thread Dave S
Dave S wrote:
Hello again  :-) ,
This script is very much a work in progress, and I think only the 
second time I have tried classes. What I expected it to do was to at 
least print 'hi there' so I know its alive, then dump some status info 
to my log program. It does zip, executes OK but no output.

I just know you guys are going to tell me I have missed a () or . 
somewhere

Any help gratefully appreciated
Dave


#!/usr/bin/env python
# -*- coding: iso8859_1 -*-
"""
arch_data.py 1.0 This is the read archive data script
"""
from os import listdir
from cPickle import load
from logger import log
from config import data_dir
debug=True
   class Arch_data:
  def __init__(self):
  self.file_names=listdir(data_dir)
   self.file_names.sort()
   self.file_name_ptr=0
  def read_next():
   """
   when executed reads next data file from data_dir extracts date,
   time,julian day,sequence count & flag from the file name.
  Also adds last_file flag and contents of file to the 
list of returned
   parameters
   """
   print 'hi there'
  file_name=self.file_names[self.file_name_ptr]
  # Ignore the archive_read.py utility script in the data dir
##if file_name=='archive_read.py':
##if debug:
##log('II','arch_data','Ignoring "archive_read.py"')
##self.file_name_ptr+=1
##read.next()
##return
  # Extract info from the encoded filename :-)
   file_yy=file_name[:4]
   file_mm=file_name[4:6]
   file_dd=file_name[6:8]
   file_HH=file_name[9:11]
   file_MM=file_name[11:13]
   file_jj=file_name[14:17]
   file_seq=file_name[18:21]
   file_flag=file_name[22:24]
  if debug:
   log('II','arch_data','unpickling '+file_name)
  pickle_file=open(data_dir+file_name,'r')
   file=load(pickle_file)
   pickle_file.close()
  print 
file_yy,file_mm,file_dd,file_HH,file_MM,file_jj,file_seq,file_flag

   self.file_name_ptr+=1
   arch_data=Arch_data()
arch_data.read_next
  ___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Dope, too quick to ask for help - sorry
def read_next(self):
and
arch_data.read_next()
sorted it :-[
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems with class, no output

2004-12-19 Thread Kent Johnson
Dave,
For some reason the indentation is very strange in this code. I think it must have something to do 
with how you posted it (or my mailer is messing it up?), as it would be a syntax error at runtime. 
If you can have more consistent indentation in your posts it will make them much easier to read.

Glad you got it working!
Kent
Dave S wrote:
Hello again  :-) ,
This script is very much a work in progress, and I think only the second 
time I have tried classes. What I expected it to do was to at least 
print 'hi there' so I know its alive, then dump some status info to my 
log program. It does zip, executes OK but no output.

I just know you guys are going to tell me I have missed a () or . somewhere
Any help gratefully appreciated
Dave


#!/usr/bin/env python
# -*- coding: iso8859_1 -*-
"""
arch_data.py 1.0 This is the read archive data script
"""
from os import listdir
from cPickle import load
from logger import log
from config import data_dir
debug=True
   class Arch_data:
  def __init__(self):
  self.file_names=listdir(data_dir)
   self.file_names.sort()
   self.file_name_ptr=0
  def read_next():
   """
   when executed reads next data file from data_dir extracts date,
   time,julian day,sequence count & flag from the file name.
  Also adds last_file flag and contents of file to the list 
of returned
   parameters
   """
   print 'hi there'
  file_name=self.file_names[self.file_name_ptr]
  # Ignore the archive_read.py utility script in the data dir
##if file_name=='archive_read.py':
##if debug:
##log('II','arch_data','Ignoring "archive_read.py"')
##self.file_name_ptr+=1
##read.next()
##return
  # Extract info from the encoded filename :-)
   file_yy=file_name[:4]
   file_mm=file_name[4:6]
   file_dd=file_name[6:8]
   file_HH=file_name[9:11]
   file_MM=file_name[11:13]
   file_jj=file_name[14:17]
   file_seq=file_name[18:21]
   file_flag=file_name[22:24]
  if debug:
   log('II','arch_data','unpickling '+file_name)
  pickle_file=open(data_dir+file_name,'r')
   file=load(pickle_file)
   pickle_file.close()
  print 
file_yy,file_mm,file_dd,file_HH,file_MM,file_jj,file_seq,file_flag

   self.file_name_ptr+=1
   arch_data=Arch_data()
arch_data.read_next
  ___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Matrix

2004-12-19 Thread Bugra Cakir
hi,

I want to create a matrix in Python. For example 3x4 how can i
create this? thanks
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Vpython

2004-12-19 Thread Aztech Guy

Hey, that's pretty good. Tried it out. VPython is cool
too.

--- "Jacob S." <[EMAIL PROTECTED]> wrote:

> > > I was wondering were can I find some Vpython
> graphics program codes that
> are readily available.
> 
> I have 2 that I am proud of.
> 
> A simple function grapher
> Usage:
> >0.125*x**2
> 
> Graphs y = 1/8*x**2
> 
> >y = 1/x
> 
> Graphs y = 1/x
> 
> >clear
> 
> Clears display window
> 
> >r = t**2
> 
> Graphs polar function r = t**2
> 
> >remove lines
> 
> Removes all axes, including polar axes, should a
> polar function be graphed
> after
> 
> >return lines
> 
> Returns all lines, so that they appear when
> appropriate.
> 
> >x = sin(x**2)+log(x**2)
> 
> Graphs the function...
> 
> 
>
--
> 
> from __future__ import division
> from visual import *
> import os
> from math import *
> ja = 0
> 
> def start():
> for objects in scene.objects:
> objects.visible = 0
> scene.title = "Function Grapher by Jacob, Inc."
> tem = raw_input('Are you on a desktop, or a
> notebook? ')
> if tem == 'desktop':
> scene.x = 365
> if tem == 'notebook':
> scene.x = 574
> scene.visible=1
> scene.exit=0
> scene.userspin = 0
> scene.range=(10,10,1)
> scene.background=(1,1,1)
> global xaxis
> global yaxis
> xaxis = curve(color=color.black)
> xaxis.append(pos=(100,0,0))
> xaxis.append(pos=(-100,0,0))
> yaxis = curve(color=color.black)
> yaxis.append(pos=(0,100,0))
> yaxis.append(pos=(0,-100,0))
> global radiusaxis
> global radiusaxis2
> radiusaxis =
> curve(pos=[(-100,-100),(100,100)],color=color.black)
> radiusaxis2 =
> curve(pos=[(-100,100),(100,-100)],color=color.black)
> radiusaxis.visible = 0
> radiusaxis2.visible = 0
> 
> start()
> y = 3
> m = 0
> t = 0
> d = 1
> print """\
> List of Commands:
> clear
> quit
> remove lines
> return lines
> 
> Function Syntax:
> var = funct a,b
> where var = what
> and funct = f(what)
> and a,b = range
> """
> 
> print 'Please type in functions in below. '
> while y != "":
> lists=[]
> y = raw_input('>')
> if y == 'clear':
> scene.visible=0
> start()
> print "-"*36
> continue
> elif y == 'quit':
> scene.visible = 0
> del scene
> break
> elif y == 'remove lines':
> a = [radiusaxis,radiusaxis2,xaxis,yaxis]
> for x in a:
> x.visible = 0
> d = 0
> continue
> elif y == 'return lines':
> a = [radiusaxis,radiusaxis2,xaxis,yaxis]
> for x in a:
> x.visible = 1
> d = 1
> continue
> if y.count('=') == 1:
> y = y.split(' = ')
> type = y[0].lower()
> y = y[1]
> y = y.replace("y","x")
> if type == 'r':
> y = y.replace('x','t')
> if d == 1:
> radiusaxis.visible = 1
> radiusaxis2.visible = 1
> else:
> type = 'y'
> y = y.split(" ")
> if len(y) > 1:
> pass
> else:
> if type == 'r':
> y.append('0,5*pi')
> else:
> y.append('-10,10')
> range = y[1]
> y = y[0]
> range = range.split(",")
> min = float(eval(range[0]))
> max = float(eval(range[1]))
> lists.append(curve(color=(1,0,1)))
> x = min
> if type == 'y' or type == 'x':
> radiusaxis.visible = 0
> radiusaxis2.visible = 0
> while x >= min and x <= max:
> x = x+0.005
> try:
> if eval(y) <= 15 and eval(y) >= -15:
> if type == 'y':
>
> lists[-1].append(pos=(x,eval(y),0))
> elif type == 'x':
>
> lists[-1].append(pos=(eval(y),x,0))
> else:
>
> lists.append(curve(color=(1,0,1)))
> except:
> pass
> elif type == 'r':
> m = 'eval(y)*cos(t)'
> n = 'eval(y)*sin(t)'
> t = min
> while t >= min and t <= max:
> try:
>
> lists[-1].append(pos=(eval(m),eval(n),0))
> except:
> lists.append(curve(color=(1,0,1)))
> t = t+0.005
> 
> 
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
> 




__ 
Do you Yahoo!? 
Send holiday email and support a worthy cause. Do good. 
http://celebrity.mail.yahoo.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: Flow chart

2004-12-19 Thread Alan Gauld
> I'm looking for any good link or tutorial of flow charting 

A good resource for all notations related to software design 
is at smartdraw.com:

http://www.smartdraw.com/exp/tec/tutorials/software.htm

But flow charts are more generic so info about them can 
be found here:

http://www.smartdraw.com/tutorials/flowcharts/resources.htm

Not entirely unbiased since I do use their tool for my personal 
use and prefer it to Visio, but the diagram tutorials are free.

And one flowchartoing tutor I can recommend is:

http://home.att.net/~dexter.a.hansen/flowchart/flowchart.htm

Downloadable as PDF too.

Alan G.
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing two elements in a list

2004-12-19 Thread Jacob S.
Would this work for you?

a = ['Name = stuff','CGTATAGCTAGCTA','Name = stuff','CGATATGCCGGCTA']
for index,thing in enumerate(a):
if "Name=" in thing:
del a[index]

I know, that it might be slow, but I thought that maybe it would hold its
own because it doesn't have to import the re module, everything's builtin,
etc.

HTH,
Jacob

 Hello group,
>  Thank you very much for your kind replies. In fact I
> survived to pull out what I needed by going with
> Kent's tip by enumerating on iterator.
>
> The problem with me is suddenly I embarked on
> something big problem and I am surviving it in pieces
> by writing pieces of code.
>
>
> I have another question:
> To be brief:
>
> My list contains some elements that I do not want and
> I want to remove unwanted elements in my list:
>
> My TEXT file looks like this:
>
> Name=32972_at
> Cell1=xxx xxx N control 32972_at
> Cell1=xxx xxx N control 32972_at
> Cell1=xxx xxx N control 32972_at
> Cell1=xxx xxx N control 32972_at
> Name=3456_at
> Cell1=xxx xxx N control 3456_at
> Cell1=xxx xxx N control 3456_at
> Cell1=xxx xxx N control 3456_at
> Cell1=xxx xxx N control 3456_at
> .   ... x   xxx
> (34K lines)
>
> I want to remove Name=Xxxx_at identifiers.
>
>
> My List:
> ['Name=32972_at',
>
'Cell1=432\t118\tN\tcontrol\t32972_at\t0\t13\tA\tA\tA\t0\t75952\t-1\t-1\t99\
t',
>
'Cell2=432\t117\tN\tcontrol\t32972_at\t0\t13\tA\tT\tA\t0\t75312\t-1\t-1\t99\
t',
>
'Cell3=499\t632\tN\tcontrol\t32972_at\t1\t13\tC\tC\tC\t1\t404979\t-1\t-1\t99
\t']
>
>
> I tried to resolve in this way:
>
> >>>pat = re.compile('Name')
> >>> for i in range(len(cord)):
> x = pat.search(cord[i])
> cord.remove(x)
>
> I know I am wrong here because I do not know how to
> search and remove an element in a list. Can any one
> please help me.
>
> on Page 98, chapter Lists and dictionaries of mark
> lutz's learning python. It is mentioned in table 6-1 :
> L2.append(4)  Methods: grow,sort,search,reverse etc.
>
>
> Although not much is covered on this aspect in this
> book, I failed to do more operations on list.
>
> Looking forward for help from tutors.
>
> Thank you.
> Kumar.
>
>
>
>
>
>
> --- Kent Johnson <[EMAIL PROTECTED]> wrote:
>
> > kumar,
> >
> > Looking at the quantity and structure of your data I
> > think the search you are doing is going to be
> > pretty slow - you will be doing 4504 * 398169 =
> > 1,793,353,176 string searches.
> >
> > Where does the seq data come from? Could you
> > consolidate the pairs of lines into a single record?
> > If
> > you do that and extract the '399:559' portion, you
> > could build a dict that maps '399:559' to the
> > full record. Looking up '399:559' in the dictionary
> > would be much, much faster than searching the
> > entire list.
> >
> > If you have multiple entries for '399:559' you could
> > have the dict map to a list.
> >
> > Kent
> >
> > kumar s wrote:
> > >
> > len(x)
> > >
> > > 4504
> > >
> > x[1:10]
> > >
> > > ['454:494', '319:607', '319:608', '322:289',
> > > '322:290', '183:330', '183:329', '364:95',
> > '364:96']
> > >
> > len(seq)
> > >
> > > 398169
> > >
> > seq[0:4]
> > >
> > > ['>probe:HG-U95Av2:1000_at:399:559;
> > > Interrogation_Position=1367; Antisense;',
> > > 'TCTCCTTTGCTGAGGCCTCCAGCTT',
> > > '>probe:HG-U95Av2:1000_at:544:185;
> > > Interrogation_Position=1379; Antisense;',
> > > 'AGGCCTCCAGCTTCAGGCAGGCCAA']
> > >
> > >
> > >
> > for ele1 in x:
> > >
> > > for ele2 in seq:
> > > if ele1 in ele2:
> > > print ele2
> > >
> > >
> > >
> > >>probe:HG-U95Av2:31358_at:454:493;
> > >
> > > Interrogation_Position=132; Antisense;
> > >
> > >>probe:HG-U95Av2:31358_at:319:607;
> > >
> > > Interrogation_Position=144; Antisense;
> > >
> > >
> > >
> > >
> > >
> > >
> > > How Do I WANT:
> > >
> > > I want to print get an output like this:
> > >
> > >
> > >
> > >>probe:HG-U95Av2:1000_at:399:559;
> > >
> > > Interrogation_Position=1367; Antisense;'
> > > TCTCCTTTGCTGAGGCCTCCAGCTT
> > >
> > >
> > >>probe:HG-U95Av2:1000_at:544:185;
> > >
> > > Interrogation_Position=1379; Antisense;
> > > AGGCCTCCAGCTTCAGGCAGGCCAA
> > >
> > >
> > > can any one please suggest what is going wrong in
> > my
> > > statements and how can I get it.
> > >
> > > Thank you.
> > > Kumar
> > >
> > >
> > >
> > > __
> > > Do you Yahoo!?
> > > Yahoo! Mail - 250MB free storage. Do more. Manage
> > less.
> > > http://info.mail.yahoo.com/mail_250
> > > ___
> > > Tutor maillist  -  [EMAIL PROTECTED]
> > > http://mail.python.org/mailman/listinfo/tutor
> > >
> > ___
> > Tutor maillist  -  [EMAIL PROTECTED]
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
>
> __
> Do you Yahoo!?
> Yahoo! Mail - now with 250MB free storage. Learn more.
> http://info.mail.yahoo.com/mail_250
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.o

Re: [Tutor] Problems with class, no output

2004-12-19 Thread Dave S
Kent Johnson wrote:
Dave,
For some reason the indentation is very strange in this code. I think 
it must have something to do with how you posted it (or my mailer is 
messing it up?), as it would be a syntax error at runtime. If you can 
have more consistent indentation in your posts it will make them much 
easier to read.

Glad you got it working!
Kent

Point taken, I had copied & pasted into my email, looked OK when I 
pasted it, but on re-opening my own email, Yuk. I will attatch file in 
future,

Cheers
Dave
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Matrix

2004-12-19 Thread Brian van den Broek
Bugra Cakir said unto the world upon 2004-12-19 10:33:
hi,
I want to create a matrix in Python. For example 3x4 how can i
create this? thanks
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
Hi,
at least two ways using only builtins occur to me:
1) A list of lists:
.>>> row1 = [4, 6, 8, 1]
.>>> row2 = [2, 5, 1, 3]
.>>> row3 = [2, 1, 2, 8]
.>>> my_matrix_as_lists = [row1, row2, row3]
.>>> print my_matrix_as_lists[1][1]
5
Note that
>>> row1[1]
6
since indicies start at 0.
2) To get around that, and be more efficient with matricies with many 
empty cells:
.>>> my_matrix_as_dict = {(1,1):4, (1,2):6, (1,3):8,
 (2,1):56, (2,3):12,
 (3,1):3, (3,2):3}

.>>> my_matrix_as_dict[(3,1)]
3
.>>> my_matrix_as_dict[(2,1)]
56
So, you just can use the tuple co-ordinates you've defined in order to 
access cells. Note also that the list way you'd have to represent empty 
cells with a standard null value -- None is the usual choice. But this 
way, you just don't define some tuples as keys, as I didn't define (2,2) 
as a key. Thus:

.>>> my_matrix_as_dict[(2,2)]
Traceback (most recent call last):
  File "", line 1, in -toplevel-
my_matrix_as_dict[(2,2)]
KeyError: (2, 2)
You can make that more graceful with a try/except block:
.>>> try:
my_matrix_as_dict[(2,2)]
except KeyError:
print "That cell is empty"

That cell is empty
.>>>
HTH,
Brian vdB
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: Flow chart

2004-12-19 Thread Brian van den Broek
Alan Gauld said unto the world upon 2004-12-19 12:23:
I'm looking for any good link or tutorial of flow charting 

A good resource for all notations related to software design 
is at smartdraw.com:

http://www.smartdraw.com/exp/tec/tutorials/software.htm
But flow charts are more generic so info about them can 
be found here:

http://www.smartdraw.com/tutorials/flowcharts/resources.htm
Not entirely unbiased since I do use their tool for my personal 
use and prefer it to Visio, but the diagram tutorials are free.

And one flowchartoing tutor I can recommend is:
http://home.att.net/~dexter.a.hansen/flowchart/flowchart.htm
Downloadable as PDF too.
Alan G.
Hi all,
thanks for sending those links, Alan. It got me curious, and I googled 
around a bit.

I found the GPL'ed Dia , which says 
it aims to be Visio like and is working on including Python scriptability.

Just thought I'd flag that.
Best to all,
Brian vdB
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: Flow chart

2004-12-19 Thread Juan Shen
Brian van den Broek wrote:
Alan Gauld said unto the world upon 2004-12-19 12:23:
I'm looking for any good link or tutorial of flow charting 

A good resource for all notations related to software design is at 
smartdraw.com:

http://www.smartdraw.com/exp/tec/tutorials/software.htm
But flow charts are more generic so info about them can be found here:
http://www.smartdraw.com/tutorials/flowcharts/resources.htm
Not entirely unbiased since I do use their tool for my personal use 
and prefer it to Visio, but the diagram tutorials are free.

And one flowchartoing tutor I can recommend is:
http://home.att.net/~dexter.a.hansen/flowchart/flowchart.htm
Downloadable as PDF too.
Alan G.

Hi all,
thanks for sending those links, Alan. It got me curious, and I googled 
around a bit.

I found the GPL'ed Dia , which 
says it aims to be Visio like and is working on including Python 
scriptability.

Just thought I'd flag that.
Best to all,
Brian vdB
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
Maybe Dia is not stronger than Visio or SmartDraw, far to be improved.  
But after all, it's GPL not commercial. 
   Juan


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Vpython

2004-12-19 Thread Juan Shen




If you need to plot many math pictures, try SciPy
    http://www.scipy.org/
I have galanced VPython's website and tutorial.  It seems it handles
3D-Plotting even better.
    Juan

Aztech Guy wrote:

  Hey, that's pretty good. Tried it out. VPython is cool
too.

--- "Jacob S." <[EMAIL PROTECTED]> wrote:

  
  

  
I was wondering were can I find some Vpython

  

graphics program codes that
are readily available.

I have 2 that I am proud of.

A simple function grapher
Usage:


  0.125*x**2
  

Graphs y = 1/8*x**2



  y = 1/x
  

Graphs y = 1/x



  clear
  

Clears display window



  r = t**2
  

Graphs polar function r = t**2



  remove lines
  

Removes all axes, including polar axes, should a
polar function be graphed
after



  return lines
  

Returns all lines, so that they appear when
appropriate.



  x = sin(x**2)+log(x**2)
  

Graphs the function...




  
  --
  
  
from __future__ import division
from visual import *
import os
from math import *
ja = 0

def start():
for objects in scene.objects:
objects.visible = 0
scene.title = "Function Grapher by Jacob, Inc."
tem = raw_input('Are you on a desktop, or a
notebook? ')
if tem == 'desktop':
scene.x = 365
if tem == 'notebook':
scene.x = 574
scene.visible=1
scene.exit=0
scene.userspin = 0
scene.range=(10,10,1)
scene.background=""
global xaxis
global yaxis
xaxis = curve(color=color.black)
xaxis.append(pos=(100,0,0))
xaxis.append(pos=(-100,0,0))
yaxis = curve(color=color.black)
yaxis.append(pos=(0,100,0))
yaxis.append(pos=(0,-100,0))
global radiusaxis
global radiusaxis2
radiusaxis =
curve(pos=[(-100,-100),(100,100)],color=color.black)
radiusaxis2 =
curve(pos=[(-100,100),(100,-100)],color=color.black)
radiusaxis.visible = 0
radiusaxis2.visible = 0

start()
y = 3
m = 0
t = 0
d = 1
print """\
List of Commands:
clear
quit
remove lines
return lines

Function Syntax:
var = funct a,b
where var = what
and funct = f(what)
and a,b = range
"""

print 'Please type in functions in below. '
while y != "":
lists=[]
y = raw_input('>')
if y == 'clear':
scene.visible=0
start()
print "-"*36
continue
elif y == 'quit':
scene.visible = 0
del scene
break
elif y == 'remove lines':
a = [radiusaxis,radiusaxis2,xaxis,yaxis]
for x in a:
x.visible = 0
d = 0
continue
elif y == 'return lines':
a = [radiusaxis,radiusaxis2,xaxis,yaxis]
for x in a:
x.visible = 1
d = 1
continue
if y.count('=') == 1:
y = y.split(' = ')
type = y[0].lower()
y = y[1]
y = y.replace("y","x")
if type == 'r':
y = y.replace('x','t')
if d == 1:
radiusaxis.visible = 1
radiusaxis2.visible = 1
else:
type = 'y'
y = y.split(" ")
if len(y) > 1:
pass
else:
if type == 'r':
y.append('0,5*pi')
else:
y.append('-10,10')
range = y[1]
y = y[0]
range = range.split(",")
min = float(eval(range[0]))
max = float(eval(range[1]))
lists.append(curve(color=(1,0,1)))
x = min
if type == 'y' or type == 'x':
radiusaxis.visible = 0
radiusaxis2.visible = 0
while x >= min and x <= max:
x = x+0.005
try:
if eval(y) <= 15 and eval(y) >= -15:
if type == 'y':
   
lists[-1].append(pos=(x,eval(y),0))
elif type == 'x':
   
lists[-1].append(pos=(eval(y),x,0))
else:
   
lists.append(curve(color=(1,0,1)))
except:
pass
elif type == 'r':
m = 'eval(y)*cos(t)'
n = 'eval(y)*sin(t)'
t = min
while t >= min and t <= max:
try:
   
lists[-1].append(pos=(eval(m),eval(n),0))
except:
lists.append(curve(color=(1,0,1)))
t = t+0.005


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


  
  


		
__ 
Do you Yahoo!? 
Send holiday email and support a worthy cause. Do good. 
http://celebrity.mail.yahoo.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


  




___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Matrix

2004-12-19 Thread Juan Shen
Try SciPy.
   http://www.scipy.org/
It has mat class to handle matrix and much else.
   Juan
Bugra Cakir wrote:
hi,
I want to create a matrix in Python. For example 3x4 how can i
create this? thanks
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
 


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Matrix

2004-12-19 Thread Rob Kapteyn
Hello to the list !
A list of lists is the most logical construction.
But -- you don't need to assemble the rows separately --
this works too:
>>> my_matrix_as_lists = [ [4, 6, 8, 1],\
...   [2, 5, 1, 3],\
...   [2, 1, 2, 8] ]
>>> print my_matrix_as_lists[1][1]
5
Rob
On Dec 19, 2004, at 1:31 PM, Brian van den Broek wrote:
Bugra Cakir said unto the world upon 2004-12-19 10:33:
hi,
I want to create a matrix in Python. For example 3x4 how can i
create this? thanks
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
Hi,
at least two ways using only builtins occur to me:
1) A list of lists:
.>>> row1 = [4, 6, 8, 1]
.>>> row2 = [2, 5, 1, 3]
.>>> row3 = [2, 1, 2, 8]
.>>> my_matrix_as_lists = [row1, row2, row3]
.>>> print my_matrix_as_lists[1][1]
5
Note that
>>> row1[1]
6
since indicies start at 0.
2) To get around that, and be more efficient with matricies with many 
empty cells:
.>>> my_matrix_as_dict = {(1,1):4, (1,2):6, (1,3):8,
 (2,1):56, (2,3):12,
 (3,1):3, (3,2):3}

.>>> my_matrix_as_dict[(3,1)]
3
.>>> my_matrix_as_dict[(2,1)]
56
So, you just can use the tuple co-ordinates you've defined in order to 
access cells. Note also that the list way you'd have to represent 
empty cells with a standard null value -- None is the usual choice. 
But this way, you just don't define some tuples as keys, as I didn't 
define (2,2) as a key. Thus:

.>>> my_matrix_as_dict[(2,2)]
Traceback (most recent call last):
  File "", line 1, in -toplevel-
my_matrix_as_dict[(2,2)]
KeyError: (2, 2)
You can make that more graceful with a try/except block:
.>>> try:
my_matrix_as_dict[(2,2)]
except KeyError:
print "That cell is empty"

That cell is empty
.>>>
HTH,
Brian vdB
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Matrix

2004-12-19 Thread Rob Kapteyn
Juan:
Thanks for the tip, but the correct address seems to be:
http://www.scipy.com/
the .org does not answer.
Now I have to check out the graphing tools they have:-)
Rob
On Dec 19, 2004, at 8:01 PM, Juan Shen wrote:
Try SciPy.
   http://www.scipy.org/
It has mat class to handle matrix and much else.
   Juan
Bugra Cakir wrote:
hi,
I want to create a matrix in Python. For example 3x4 how can i
create this? thanks
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Matrix

2004-12-19 Thread Brian van den Broek
Rob Kapteyn said unto the world upon 2004-12-19 22:44:
Hello to the list !
A list of lists is the most logical construction.
But -- you don't need to assemble the rows separately --
this works too:
 >>> my_matrix_as_lists = [ [4, 6, 8, 1],\
...   [2, 5, 1, 3],\
...  [2, 1, 2, 8] ]
 >>> print my_matrix_as_lists[1][1]
5
Rob
On Dec 19, 2004, at 1:31 PM, Brian van den Broek wrote:
Bugra Cakir said unto the world upon 2004-12-19 10:33:
hi,
I want to create a matrix in Python. For example 3x4 how can i
create this? thanks
Hi,
at least two ways using only builtins occur to me:
1) A list of lists:
.>>> row1 = [4, 6, 8, 1]
.>>> row2 = [2, 5, 1, 3]
.>>> row3 = [2, 1, 2, 8]
.>>> my_matrix_as_lists = [row1, row2, row3]
.>>> print my_matrix_as_lists[1][1]
5

HTH,
Brian vdB
Sure, there's no need to assemble the rows separately. But, if you 
collapse it as you did, there is no need for the line continuations, 
either. Since all the lines are enclosed within brackets, if you want to 
span multiple lines, you can just as well do:

.>>> my_matrix_as_lists = [ [4, 6, 8, 1],
[2, 5, 1, 3],
[2, 1, 2, 8] ]
Best to all,
Brian vdB
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: Printing two elements in a list

2004-12-19 Thread C Smith
Jacob S. wrote:
Would this work for you?
a = ['Name = stuff','CGTATAGCTAGCTA','Name = stuff','CGATATGCCGGCTA']
for index,thing in enumerate(a):
if "Name=" in thing:
del a[index]
I know, that it might be slow, but I thought that maybe it would hold 
its
own because it doesn't have to import the re module, everything's 
builtin,
etc.

Be careful here, the above code will miss deleting an element 
containing "Name=" if there are two in a row.  Look at this simple 
example where we attempt to delete elements equal to 2:

###
>>> a=[1,2,1,2]
>>> for i,x in enumerate(a):
..  if x==2:del a[i]
..
>>> a
[1, 1]
>>> #
>>> # ok that looks right, but watch this
>>> #
>>> b=[2,2,1,1]
>>> for i,x in enumerate(b):
..   if x==2: del b[i]
..
>>> b
[2, 1, 1]
###
After deleting element 0 in b, all the elements "slid down" one place 
and the 2nd 2 that was in b is now in position 0...but you are moving 
on to index 1 with the enumerate loop:

[2, 2, 1, 1]
 ^
 enumerate is at index 0
we delete element 0
[2, 1, 1]
^
enumerate is at index 1 and the 2 that was at position 1 is now at 
position 0

An alternative is to use a list comprehension, keeping only the 
elements that are not 2. As is shown, you can replace the list you are 
filtering with the filtered result:

###
>>> b=[2,2,1,1]
>>> b=[x for x in b if not(x==2)]
>>> b
[1, 1]
###
/c
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor