Re: [Tutor] how to seed up?

2007-05-19 Thread alejandro varas

hi list
 this is an answer to your first question
 I put two attachments, both python code
 main.py is the file you have to run and
 script.py is the file that must contain your code

 Howto:
   1.- run main.py and your code will be executed
   2.- then you will be answered to do it again, don't answer right now
   3.- modify your code, save it
   4.- answer in any Pythonic way of True or False( obviously True to run
again and False to stop)

HTH

2007/5/19, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:


hi list

when i have many modules in my script (eg. 'import pylab,
os, sys'), python loads them very slow ...

so is there a way to run same script many times (with small
changes in the code), without reloading/parsing all modules
each time ?

and 2nd question - in case of CGI script - is there a way to
recall faster already loaded/called script?

Regards,
e.

-

SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и
технологии.
http://www.bgscena.com/

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





--
Alejandro Varas G.
T.N.S. en Redes de Computadores.(estudiante)
http://alej0varas.googlepages.com
+56998330920
#!/usr/bin/python

#import what you need once
import string

again = True

while again:
  #here you can read your modified code once and again
  f = open("script.py")
  #now run the code
  exec(f)
  #simple way to do it again or go away
  again = int( raw_input("Run again? "))#1 or 0
#use the modules you import in main.py
a = string.split("ASDFASDFSADF", "A")
print a
#comment or uncomment next line to se de diference
#print "this time I am the modified code"
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I want some help with arrays...

2007-05-19 Thread alejandro varas

2007/5/18, Luke Paireepinart <[EMAIL PROTECTED]>:


James Matthews wrote:
> When the CPU writes to the RAM the 0th location can be written to also.
When
> you alter components of a language for example changing the way an list
is
> indexed you have to be careful because you can accidently jump out of
> bounds!
def indexOneBased(somelist,index):
   return somelist[index-1]

now you can do
indexOneBased([1,2,3,4,5], 5)
and you will get 5.

Obviously the verbosity of this example seems to imply its uselessness,
but what Bob was getting at is that there are situations where you can
create a list that you index into based upon some arbitrary starting
point.
For example, say you had a calendar program that kept track of my
schedule for days 1 through 31 of this month.
You'd store the schedule of each day in a list starting with the 0th
element and ending at the 30th element.
Then, whenever I asked you for the 1st element, for example, you'd
retrieve the 0th element for me, and so on.
The indexing itself isn't changed, merely the interface to it.
Note that you don't actually index the list starting at the 1th element
(the 2nd one)
you index it starting at the 0th element, but use indexes that begin at 1.



if you want something like a calendar i thin is beter to use adictionary
where you can do this
agenda =
{
 'month' :
 {
   'day':
   { ...
   },
 },
}

so you don't have to deal whit indexes you jut wet what you want by doing

month = "month"
day = "day"

agenda[month][day]

HTH,

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





--
Alejandro Varas G.
T.N.S. en Redes de Computadores.(estudiante)
http://alej0varas.googlepages.com
+56998330920
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] curses

2007-08-03 Thread alejandro varas
maybe dis is what you want to do. Ijust made some changes to the code.




On 7/17/07, max baseman <[EMAIL PROTECTED]> wrote:
>
> hello all sorry to bother I'm working on my first curses program ive
> been wanting to learn curses for a while now and now that a have a
> lop top with fedora core running in run level 3 ware im trying to
> program all the tools i'll use but curses will be my only gui ALAN
> has been helping me with this program
>
> import curses
> from time import sleep
> scr=curses.initscr()
> population=0
> seconds=0
> try:
>  scr.nodelay(1)
>  scr.leaveok(0)
>  max_y, max_x = scr.getmaxyx()
>  while 1:
>  sleep(1)
>  second=seconds=+1

 population=population+2.5
>  scr.addstr(0,0,"seconds",seconds)

scr.addch,max_y/2, max_x/2, str(population)[0]
scr.refresh()

> finally:
>  curses.endwin()
>
>
> depending on ware i run this i get different results on may mac OSX
> 10.4 i only get a wired second thing in the top left corner that
> looks like this secooes
>
> and when i run this on fedora core 6 i get the seconds word in top
> left but no number and i get a single digit in the midle that changes
> i think the single digit is part of population but not all i cant
> find out what is wrong
>
>
> any help would be great :)
> _______
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Alejandro Varas G.
T.N.S. en Redes de Computadores.
http://alej0varas.googlepages.com
+56984350861
import curses
from time import sleep
scr=curses.initscr()
population=0
seconds=0
try:
	scr.nodelay(1)
	scr.leaveok(0)
	max_y, max_x = scr.getmaxyx()
	while 1:
		sleep(1)
		seconds += 1
#second  should be seconds whit an "s"
	population += 2.5

#if you want seconds to be printed on the screen do this
	scr.addstr( 0,0,"seconds %d" % seconds )

#and here you do a big mistake, you forget the ()
	scr.addstr( max_y/2, max_x/2, str(population) )

	scr.refresh()
finally:
	curses.endwin()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor