Re: [Tutor] regex problem with colon

2009-08-06 Thread Tim Johnson
* Kent Johnson  [090806 18:31]:
> On Thu, Aug 6, 2009 at 8:47 PM, Tim Johnson wrote:
> > using python 2.5.
> > I'm having a problem with including a colon as part of a substring
> > bounded by whitespace or beginning of line.
> > Here's an example:
> > p = re.compile(r'\bcc:\b',re.IGNORECASE)
>  res = p.findall('malicious cc: here CC: there')
>  res
> > []
> > ## Darn! I'd hope that the 'cc:' and 'CC:' substrings would be
> > found. So how to compose the expression correctly?
> 
> The problem is that : is not a "word" character, so there is no word
> boundary between : and space for \b to match. How about this:
> In [9]: p = re.compile(r'\bcc:',re.IGNORECASE)
 
  Yes. You nailed it Kent.
  I had grokked the logic but not entirely the syntax.
  I'm looking thru docs now. Just curious .. is there a flag that
  enables adding a ':' to the internal list of "word" characters?

> In [10]: p.findall('malicious cc: here CC: there')
> Out[10]: ['cc:', 'CC:']

thanks again.
-- 
Tim 
t...@johnsons-web.com
http://www.akwebsoft.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regex problem with colon

2009-08-06 Thread Kent Johnson
On Thu, Aug 6, 2009 at 8:47 PM, Tim Johnson wrote:
> using python 2.5.
> I'm having a problem with including a colon as part of a substring
> bounded by whitespace or beginning of line.
> Here's an example:
> p = re.compile(r'\bcc:\b',re.IGNORECASE)
 res = p.findall('malicious cc: here CC: there')
 res
> []
> ## Darn! I'd hope that the 'cc:' and 'CC:' substrings would be
> found. So how to compose the expression correctly?

The problem is that : is not a "word" character, so there is no word
boundary between : and space for \b to match. How about this:
In [9]: p = re.compile(r'\bcc:',re.IGNORECASE)

In [10]: p.findall('malicious cc: here CC: there')
Out[10]: ['cc:', 'CC:']

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


Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote:
> 
> 
>> Martin Walsh 
>>
> 
>> Allen Fowler wrote:
>>> As a follow-up question, how do give my modules stored under ./lib access 
>>> to 
>> the data in my ConfigParser object?  (For instance, database connection 
>> string, 
>> storage path, etc.)
>>> I guess a global ConfigParser object would work, but that seems wrong.
>>>
>> And yet, to me it seems wrong to have more than one instance of config
>> data floating around. Instead of using a global you can pass the config
>> object, or just the appropriate attributes, around to your lib
>> functions/classes, as necessary -- and keep the flow in your main
>> script. For example (highly speculative, FWIW),
>>
>> # app.py
>> from database.connection import getcursor
>> from lib.persist import Storage
>>
>> def main():
>> confp = ConfigParser()
>> confp.read(join_relative(__file__, 'config/prefs.ini'))
>> config = confp.defaults()
>>
>> curs = getcursor(config[db_connection_string])
>>
>> ...
>>
>> storage = Storage(config[storage_path])
>>
>>
> 
> 
> I hear your point.  It makes sense.
> 
> 
> The above sample code seems like the way to go... if I can structure my 
> modules like that.
> 
> For an object that needs many settings, what about passing in an instance of 
> ConfigParser?  (Or should I extract the settings to a dict, first?)
> 
> Thank you again,
> :)
> 

I don't see a problem with either of those approaches -- I suppose it
depends a little on the kind of config data you're working with, the
overall design of your app, which approach would be easiest to maintain.

If your intent is to package software that the general public will use,
then I believe Alan and Dave have correctly advised to follow the
packaging conventions for your target platform(s), and to be consistent
with user expectations (ie. how do popular apps typically handle config?)

I tend to write a lot of system automation scripts (sysadmin-style),
where I'm one of the few internal end users, and my toolbox module
contains wrappers for the various sources of config data (configparser,
optparse, os.environ, etc) each providing a common interface that I like
to use (and remember easily!) for dealing with config data in new
function and class definitions. But I use these a lot, and wouldn't
necessarily recommend the approach if you only need to consume config
data now and again. I think the point I may be trying to make is that it
took me a while to settle, after much trial and error, to find the
approach that works best for me -- others will have a different story to
tell, and I hope they do! :)

Good luck!

Marty

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


Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote:
> 
> 
> 
>> Something like this ...
>>
>> # lib/mypaths.py
>> # --
>>
>> import os
>>
>> def script_path(base):
>> return os.path.realpath(os.path.abspath(base))
>>
>> def script_dir(base):
>> return os.path.dirname(script_path(base))
>>
>> def join_relative(base, path):
>> return os.path.join(script_dir(base), path)
>>
>> # app.py
>> # --
>>
>> ...
>>
>> from lib.mypaths import join_relative
>> print join_relative(__file__, 'config/prefs.ini')
>>
>> # this may work when calling from
>> # other modules, I suppose (untested)
>>
>> import sys
>> print join_relative(sys.argv[0], 'config/prefs.ini')
>>
>> ...
> 
> 
> FWIW:
> 
> When using relative paths I got extra ../../ terms, so I changed  
> join_relative() to:
> 
> def join_relative(base, path):
> return os.path.normpath(os.path.join(script_dir(base), path))
> 
> 
> Seems to work...


Yeah, good catch ... looks great, and thanks for sharing your mod.

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


[Tutor] regex problem with colon

2009-08-06 Thread Tim Johnson
using python 2.5.
I'm having a problem with including a colon as part of a substring
bounded by whitespace or beginning of line.
Here's an example:
p = re.compile(r'\bcc:\b',re.IGNORECASE)
>>> res = p.findall('malicious cc: here CC: there')
>>> res
[]
## Darn! I'd hope that the 'cc:' and 'CC:' substrings would be
found. So how to compose the expression correctly?
TIA
-- 
Tim 
t...@johnsons-web.com
http://www.akwebsoft.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2009-08-06 Thread Alan Gauld


"jonathan wallis"  wrote


from pygame.locals import *
from pygame.color import THECOLORS

if not pygame.font:
   print 'Atention, there are no fonts.'

if not pygame.mixer:
   print 'Atention, there is no sound.'

pygame.init()

blue = (0, 0, 255)
red = (255, 0, 0)
black = (0, 0, 0)

window_width = 1280
window_height = 960

window = pygame.display.set_mode((window_width, window_height))

def circle_func(color, xpos, ypos, ray, movement_x, movment_y):
   circle = pygame.draw.circle(window, color, (xpos, ypos), ray)
   return circle

   key_pressed = pygame.key.get_pressed()

   if key_pressed[K_LEFT]:
   xpos -= movement_x

   if key_pressed[K_DOWN]:
   ypos += movement_y


when you try to move the circles with the left, right, down or up arrow 
keys
it spits out an error saying "xpos is not defined" or "ypos is not 
defined"


So where do you think you define xpos and ypos?
You cannot use them until you define them by assigning a value.

xpos -= movement_x

is just shorthand for

xpos = xpos -  movement_x

You cannot use xpos on the right before you give it an initial value.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



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


Re: [Tutor] clear screen inside python interpreter

2009-08-06 Thread Alan Gauld


"Monte Milanuk"  wrote

Okay, simple question: is there anything similar to to 'clear' or 'cls' 
to

clean up a console window full of commands in the python shell?  Short of
exiting and restarting the interpreter I'm not having a lot of luck here.


Terminal control is very system dependant.
Fred Lundh did crate a platform independant console module that
allowed cursor control and clearing of screens etc. Google should
find it for you.

But in your case os.system() or subprocess.call() are probably your
best bet. or just print('\n' *100)


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



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


Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Alan Gauld


"Allen Fowler"  wrote 

For an object that needs many settings, what about passing 
in an instance of ConfigParser?  (Or should I extract the 
settings to a dict, first?)


Personally I usually extract an ini type settings to either global 
variables or an object or a dict at start up., I then pass that data 
around in my functions.


HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Alan Gauld


"Che M"  wrote 


C:\Windows> python some\path\to\myscript.py



That way you will still see the error message after the
program finishes.


Or what about using IDLE?  


Good point, although IDLE can bring its own problems.
But for this case IDLE would be a good choice.



--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p

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


Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler




> 
> Something like this ...
> 
> # lib/mypaths.py
> # --
> 
> import os
> 
> def script_path(base):
> return os.path.realpath(os.path.abspath(base))
> 
> def script_dir(base):
> return os.path.dirname(script_path(base))
> 
> def join_relative(base, path):
> return os.path.join(script_dir(base), path)
> 
> # app.py
> # --
> 
> ...
> 
> from lib.mypaths import join_relative
> print join_relative(__file__, 'config/prefs.ini')
> 
> # this may work when calling from
> # other modules, I suppose (untested)
> 
> import sys
> print join_relative(sys.argv[0], 'config/prefs.ini')
> 
> ...


FWIW:

When using relative paths I got extra ../../ terms, so I changed  
join_relative() to:

def join_relative(base, path):
return os.path.normpath(os.path.join(script_dir(base), path))


Seems to work...


  

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


Re: [Tutor] monitor number of files in a folder

2009-08-06 Thread Νικόλαος Ράπτης
Well, os.listdir doesn't include "." or ".." anyway as you can see here 


So, just a simplelen(os.listdir(my_directory))will suffice..

A couple more points:
-It's better looking and more readable (to me that means Pythonic) to 
store that ugly path to a variable first.
-Whenever you see yourself repeating a chunk of code, make a function 
out of it!



So, your program now is
--
import os, time

my_directory = 
'/Volumes/sgtb/lac/comps/Z353_002/renders/Z353_002_comp/Z353_002_comp_v04/2048x1556'


while len(os.listdir(my_directory)) <= 8:
  print 'waiting'
  time.sleep(5)
  print 'still waiting'
  time.sleep(5)

print 'eight'
---


Nick (also, this is my first post)

pedro wrote:
I got it working but it seems little clunky. If I have a folder with 6 
files in it, python will print out "waiting, still waiting, waiting, 
still waiting..." if I add 3 new file to the folder python prints 
"eight". This is the basic behaviour I want but is there a more 
pythonic way to write this.




import os, time

theFilesAsList = []

for anItem in 
os.listdir('/Volumes/sgtb/lac/comps/Z353_002/renders/Z353_002_comp/Z353_002_comp_v04/2048x1556'): 




  if anItem[0] != ".":
   theFilesAsList.append(anItem)
theNumberOfImages = len(theFilesAsList)

while theNumberOfImages <= 8:
   print 'waiting'
   time.sleep(5)
   print 'still waiting'
   time.sleep(5)
   theFilesAsList = []
   for anItem in 
os.listdir('/Volumes/sgtb/lac/comps/Z353_002/renders/Z353_002_comp/Z353_002_comp_v04/2048x1556'): 




  if anItem[0] != ".":
   theFilesAsList.append(anItem)
   theNumberOfImages = len(theFilesAsList)
print 'eight'


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



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


Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler



> Martin Walsh 
>

> Allen Fowler wrote:
> > 
> 
> > 
> > As a follow-up question, how do give my modules stored under ./lib access 
> > to 
> the data in my ConfigParser object?  (For instance, database connection 
> string, 
> storage path, etc.)
> > 
> > I guess a global ConfigParser object would work, but that seems wrong.
> > 
> 
> And yet, to me it seems wrong to have more than one instance of config
> data floating around. Instead of using a global you can pass the config
> object, or just the appropriate attributes, around to your lib
> functions/classes, as necessary -- and keep the flow in your main
> script. For example (highly speculative, FWIW),
> 
> # app.py
> from database.connection import getcursor
> from lib.persist import Storage
> 
> def main():
> confp = ConfigParser()
> confp.read(join_relative(__file__, 'config/prefs.ini'))
> config = confp.defaults()
> 
> curs = getcursor(config[db_connection_string])
> 
> ...
> 
> storage = Storage(config[storage_path])
> 
>


I hear your point.  It makes sense.


The above sample code seems like the way to go... if I can structure my modules 
like that.

For an object that needs many settings, what about passing in an instance of 
ConfigParser?  (Or should I extract the settings to a dict, first?)

Thank you again,
:)


  

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


[Tutor] need help

2009-08-06 Thread jonathan wallis
i am in the process of creating a simple python program, and i have come
across a problem which i can not solve, here is the code


*import pygame
from pygame.locals import *
from pygame.color import THECOLORS

if not pygame.font:
print 'Atention, there are no fonts.'

if not pygame.mixer:
print 'Atention, there is no sound.'

pygame.init()

blue = (0, 0, 255)
red = (255, 0, 0)
black = (0, 0, 0)


window_width = 1280
window_height = 960

window = pygame.display.set_mode((window_width, window_height))

def circle_func(color, xpos, ypos, ray, movement_x, movment_y):
circle = pygame.draw.circle(window, color, (xpos, ypos), ray)
return circle

circle = circle_func(red, 50, 50, 20, 3, 3)
circle2 = circle_func(blue, 100, 100, 10, 3, 3)


pygame.display.flip()

pygame.key.set_repeat(1000, 100)

while True:
for event in pygame.event.get():
pass

key_pressed = pygame.key.get_pressed()

if key_pressed[K_LEFT]:
xpos -= movement_x

if key_pressed[K_RIGHT]:
xpos += movement_x


if key_pressed[K_UP]:
ypos -= movement_y

if key_pressed[K_DOWN]:
ypos += movement_y

window.fill(black)
circle = circle_func(red, 50, 50, 20, 3, 3)
circle2 = circle_func(blue, 100, 100, 10, 3, 3)
pygame.display.flip()*

when you try to move the circles with the left, right, down or up arrow keys
it spits out an error saying "xpos is not defined" or "ypos is not defined"
depending on if you hit the left/right or up/down keys, please show me what
i am doing wrong!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler




> > Assuming the application could be invoked in odd ways that may alter the 
> notion of the current working directory, how do I unambiguously find the 
> absolute path to the current python source file?  (So I can load the nearby 
> .ini)
> 
> I use a helper function that calculates the absolute path of my app
> script, then I am able to os.path.join relative elements to my heart's
> content. I haven't had a problem with this approach so far, which of
> course doesn't mean it's the right way, or even a correct implementation
> for that matter.
> 
> Something like this ...
> 
> # lib/mypaths.py
> # --
> 
> import os
> 
> def script_path(base):
> return os.path.realpath(os.path.abspath(base))
> 
> def script_dir(base):
> return os.path.dirname(script_path(base))
> 
> def join_relative(base, path):
> return os.path.join(script_dir(base), path)
> 
> # app.py
> # --
> 
> ...
> 
> from lib.mypaths import join_relative
> print join_relative(__file__, 'config/prefs.ini')
> 
> # this may work when calling from
> # other modules, I suppose (untested)
> 
> import sys
> print join_relative(sys.argv[0], 'config/prefs.ini')
> 


That is really great.  Thank you.  

I wonder why something like this is not in the standard library.  Seems like an 
often needed function.


  

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


Re: [Tutor] clear screen inside python interpreter

2009-08-06 Thread Nick Raptis

I don't think there's a Python command to do this.

You can always print enough newlines to clear your view of the window:

print "\n" * 80

or use os.system to issue a command the shell/terminal/cmd will understand

import os
os.system("cls")

or

import os
os.system("clear")


I resently made a 'game of life' clone and used the first method to 
clear the screen. It's good enough for many things!


Nick


Monte Milanuk wrote:
Okay, simple question: is there anything similar to to 'clear' or 
'cls' to clean up a console window full of commands in the python 
shell?  Short of exiting and restarting the interpreter I'm not having 
a lot of luck here.


Thanks,

Monte


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

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


[Tutor] clear screen inside python interpreter

2009-08-06 Thread Monte Milanuk
Okay, simple question: is there anything similar to to 'clear' or 'cls' to
clean up a console window full of commands in the python shell?  Short of
exiting and restarting the interpreter I'm not having a lot of luck here.

Thanks,

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


Re: [Tutor] monitor number of files in a folder

2009-08-06 Thread Dave Angel

Sander Sweers wrote:

2009/8/6 Dave Angel :
  

You have to choose your poison.



I prefer no poison. This is exactly what inotiy was made for and
although I never used it there is a python module for it [1]. It would
be great if you can post your experience with it.

Greets
Sander

[1] http://trac.dbzteam.org/pyinotify/wiki

  
pyinotify solves an interesting problem, and if it worked on Windows, I 
already have a client with an application for it.  But it has little to 
do with the OP's question.


The problem the OP had was how to break out of a while loop, if the 
single condition never got satisfied.  The simplest answer is to make a 
second condition (timeout), and use and.  But that creates a second 
problem -- what to do if it did timeout.  That's the poison he had to 
choose between.


The time when pyinotify becomes very useful is if there are a large 
number of files/directories involved, and polling would be too slow.  
Presumably, the supported OS provides some event notification when a 
file is changed, and this module builds on that.


DaveA

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


Re: [Tutor] Looking up a value in a dictionary from user input problem

2009-08-06 Thread Dave Angel

chase pettet wrote:

I am trying to write a script to work our LVS implementation.  I want to be
able to have  user do something like this "./script SITE SERVER" and have
the script look up the ip value of the site on that server and issue the
command to pull the status from LVS.  I am almost there but for some reason
when I try to pass the site parameter dynamically (the name of the
dictionary) I keep getting errors about value type.  I have two example that
work where the dictionary name is hard coded to to speak in the script, and
the value I want to pull is dynamic using sys.argv[1], and one where I'm
trying to pass the dictionary name and it does not work.  I tried to slim
thse examples down, so hopefully they are helpful:

-


Not working...

./script.py t site

#!/usr/bin/env python
site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
"s2":"10.1.1.5", "s3":"10.1.1.6"}

def runBash(cmd):
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
  out = p.stdout.read().strip()
  return out

class LVS_Site:
  def show(self, site):
showsite = "ipvsadm -L -t %s:443" % (site)
showsiteresult = runBash(showsite)
return showsiteresult

a = LVS_Site()
z = sys.argv[2]
b = b["%s" % (sys.argv[1])]
c = a.show(b)
print ""
print ""
print ""
print c

Error:

Traceback (most recent call last):
  File "./python2.py", line 22, in ?
b = z["%s" % (sys.argv[1])]
TypeError: string indices must be integers


I don't understand why the third one does not work. Thanks for any help!

  
You didn't post the exact code, as the line that gives the error is 
quoted differently than it is.  I suspect that the error message shows 
the version you actually tested.


a = LVS_Site()
z = sys.argv[2]
at this point, z is a string, containing the characters 
"site"


b = z["%s" % (sys.argv[1])]

at this point, sys.argv[1] is a string, containing the 
character "t"

So  "s" % "t"is a string, containing the character "t"
So you're trying to evaluate
   "site"["t"]
And thus the error.  Strings can be indexed only by integers, not by 
characters.


It appears you're confusing the variable site with the string "site".   
The former is a dictionary, the latter is a string.


Now, you could lookup that string in the current global namespace, and 
get the dictionary with that name.  Something like (untested):


   b = globals().get(z, None) [ "%s" % (sys.argv[1])]

But this is pretty dangerous territory.  Perhaps if you tell us what 
you're actually trying to achieve, we might be able to help.  For 
example, you might have a limited list of dictionaries, and want the 
user to be able to choose among them by keyword.



   


site_HQ = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
"s2":"10.1.1.5", "s3":"10.1.1.6"}

site_Alternate = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", 
"s1":"10.1.1.4",
"s2":"10.1.1.5", "s3":"10.1.1.6"}

site_desperate = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", 
"s1":"10.1.1.4",


"s2":"10.1.1.5", "s3":"10.1.1.6"}

sitelist = {"HQ":site_HQ, "Alternate", site_Alternate, 
"desperate":site_desperate}


b =  sitelist[sys.argv[2]] ["%s" % (sys.argv[1])]


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


Re: [Tutor] Looking up a value in a dictionary from user input problem

2009-08-06 Thread Νικόλαος Ράπτης

Hmmm.. First of all..
In the non working code:

a = LVS_Site()
z = sys.argv[2]
b = b["%s" % (sys.argv[1])]
c = a.show(b)
.

Did you really mean
b = b["%s" % (sys.argv[1])]

or perhaps
b = z["%s" % (sys.argv[1])]


Also, I can't see why your doing the string formatting in there:
b = z[sys.argv[1]]   should work. Perhaps that's because you need it 
in the 'real' program?


Nick


chase pettet wrote:
I am trying to write a script to work our LVS implementation.  I want 
to be able to have  user do something like this "./script SITE SERVER" 
and have the script look up the ip value of the site on that server 
and issue the command to pull the status from LVS.  I am almost there 
but for some reason when I try to pass the site parameter dynamically 
(the name of the dictionary) I keep getting errors about value type.  
I have two example that work where the dictionary name is hard coded 
to to speak in the script, and the value I want to pull is dynamic 
using sys.argv[1], and one where I'm trying to pass the dictionary 
name and it does not work.  I tried to slim thse examples down, so 
hopefully they are helpful:


works #1...

./script.py t

#!/usr/bin/env python
site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", 
"s1":"10.1.1.4", "s2":"10.1.1.5", "s3":"10.1.1.6"}


def runBash(cmd):
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
  out = p.stdout.read().strip()
  return out

class LVS_Site:
  def show(self, site):
showsite = "ipvsadm -L -t %s:443" % (site)
showsiteresult = runBash(showsite)
return showsiteresult

a = LVS_Site()
b = site["%s" % (sys.argv[1])]
c = a.show(b)
print ""
print ""
print ""
print c

works #2...

./script.py t

#!/usr/bin/env python
site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", 
"s1":"10.1.1.4", "s2":"10.1.1.5", "s3":"10.1.1.6"}


def runBash(cmd):
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
  out = p.stdout.read().strip()
  return out

class LVS_Site:
  def show(self, site):
showsite = "ipvsadm -L -t %s:443" % (site)
showsiteresult = runBash(showsite)
return showsiteresult

a = LVS_Site()
z = site
b = z["%s" % (sys.argv[1])]
c = a.show(b)
print ""
print ""
print ""
print c


Not working...

./script.py t site

#!/usr/bin/env python
site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", 
"s1":"10.1.1.4", "s2":"10.1.1.5", "s3":"10.1.1.6"}


def runBash(cmd):
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
  out = p.stdout.read().strip()
  return out

class LVS_Site:
  def show(self, site):
showsite = "ipvsadm -L -t %s:443" % (site)
showsiteresult = runBash(showsite)
return showsiteresult

a = LVS_Site()
z = sys.argv[2]
b = b["%s" % (sys.argv[1])]
c = a.show(b)
print ""
print ""
print ""
print c

Error:

Traceback (most recent call last):
  File "./python2.py", line 22, in ?
b = z["%s" % (sys.argv[1])]
TypeError: string indices must be integers


I don't understand why the third one does not work. Thanks for any help!


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

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


Re: [Tutor] Looking up a value in a dictionary from user input problem

2009-08-06 Thread vince spicer
On Thu, Aug 6, 2009 at 3:42 PM, vince spicer  wrote:

>
>
> On Thu, Aug 6, 2009 at 3:18 PM, chase pettet  wrote:
>
>> I am trying to write a script to work our LVS implementation.  I want to
>> be able to have  user do something like this "./script SITE SERVER" and have
>> the script look up the ip value of the site on that server and issue the
>> command to pull the status from LVS.  I am almost there but for some reason
>> when I try to pass the site parameter dynamically (the name of the
>> dictionary) I keep getting errors about value type.  I have two example that
>> work where the dictionary name is hard coded to to speak in the script, and
>> the value I want to pull is dynamic using sys.argv[1], and one where I'm
>> trying to pass the dictionary name and it does not work.  I tried to slim
>> thse examples down, so hopefully they are helpful:
>>
>> works #1...
>>
>> ./script.py t
>>
>> #!/usr/bin/env python
>> site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
>> "s2":"10.1.1.5", "s3":"10.1.1.6"}
>>
>> def runBash(cmd):
>>   p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
>>   out = p.stdout.read().strip()
>>   return out
>>
>> class LVS_Site:
>>   def show(self, site):
>> showsite = "ipvsadm -L -t %s:443" % (site)
>> showsiteresult = runBash(showsite)
>> return showsiteresult
>>
>> a = LVS_Site()
>> b = site["%s" % (sys.argv[1])]
>> c = a.show(b)
>> print ""
>> print ""
>> print ""
>> print c
>>
>> works #2...
>>
>> ./script.py t
>>
>> #!/usr/bin/env python
>> site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
>> "s2":"10.1.1.5", "s3":"10.1.1.6"}
>>
>> def runBash(cmd):
>>   p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
>>   out = p.stdout.read().strip()
>>   return out
>>
>> class LVS_Site:
>>   def show(self, site):
>> showsite = "ipvsadm -L -t %s:443" % (site)
>> showsiteresult = runBash(showsite)
>> return showsiteresult
>>
>> a = LVS_Site()
>> z = site
>> b = z["%s" % (sys.argv[1])]
>> c = a.show(b)
>> print ""
>> print ""
>> print ""
>> print c
>>
>>
>> Not working...
>>
>> ./script.py t site
>>
>> #!/usr/bin/env python
>> site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
>> "s2":"10.1.1.5", "s3":"10.1.1.6"}
>>
>> def runBash(cmd):
>>   p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
>>   out = p.stdout.read().strip()
>>   return out
>>
>> class LVS_Site:
>>   def show(self, site):
>> showsite = "ipvsadm -L -t %s:443" % (site)
>> showsiteresult = runBash(showsite)
>> return showsiteresult
>>
>> a = LVS_Site()
>> z = sys.argv[2]
>> b = b["%s" % (sys.argv[1])]
>> c = a.show(b)
>> print ""
>> print ""
>> print ""
>> print c
>>
>> Error:
>>
>> Traceback (most recent call last):
>>   File "./python2.py", line 22, in ?
>> b = z["%s" % (sys.argv[1])]
>> TypeError: string indices must be integers
>>
>>
>> I don't understand why the third one does not work. Thanks for any help!
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
> In your code
>
> z = sys.argv[2] which is a string
>
> think you want
>
> b = site[z]
>

or even better

b =  site.get(z, None)
if b is None:
print "Not Found"
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking up a value in a dictionary from user input problem

2009-08-06 Thread vince spicer
On Thu, Aug 6, 2009 at 3:18 PM, chase pettet  wrote:

> I am trying to write a script to work our LVS implementation.  I want to be
> able to have  user do something like this "./script SITE SERVER" and have
> the script look up the ip value of the site on that server and issue the
> command to pull the status from LVS.  I am almost there but for some reason
> when I try to pass the site parameter dynamically (the name of the
> dictionary) I keep getting errors about value type.  I have two example that
> work where the dictionary name is hard coded to to speak in the script, and
> the value I want to pull is dynamic using sys.argv[1], and one where I'm
> trying to pass the dictionary name and it does not work.  I tried to slim
> thse examples down, so hopefully they are helpful:
>
> works #1...
>
> ./script.py t
>
> #!/usr/bin/env python
> site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
> "s2":"10.1.1.5", "s3":"10.1.1.6"}
>
> def runBash(cmd):
>   p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
>   out = p.stdout.read().strip()
>   return out
>
> class LVS_Site:
>   def show(self, site):
> showsite = "ipvsadm -L -t %s:443" % (site)
> showsiteresult = runBash(showsite)
> return showsiteresult
>
> a = LVS_Site()
> b = site["%s" % (sys.argv[1])]
> c = a.show(b)
> print ""
> print ""
> print ""
> print c
>
> works #2...
>
> ./script.py t
>
> #!/usr/bin/env python
> site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
> "s2":"10.1.1.5", "s3":"10.1.1.6"}
>
> def runBash(cmd):
>   p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
>   out = p.stdout.read().strip()
>   return out
>
> class LVS_Site:
>   def show(self, site):
> showsite = "ipvsadm -L -t %s:443" % (site)
> showsiteresult = runBash(showsite)
> return showsiteresult
>
> a = LVS_Site()
> z = site
> b = z["%s" % (sys.argv[1])]
> c = a.show(b)
> print ""
> print ""
> print ""
> print c
>
>
> Not working...
>
> ./script.py t site
>
> #!/usr/bin/env python
> site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
> "s2":"10.1.1.5", "s3":"10.1.1.6"}
>
> def runBash(cmd):
>   p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
>   out = p.stdout.read().strip()
>   return out
>
> class LVS_Site:
>   def show(self, site):
> showsite = "ipvsadm -L -t %s:443" % (site)
> showsiteresult = runBash(showsite)
> return showsiteresult
>
> a = LVS_Site()
> z = sys.argv[2]
> b = b["%s" % (sys.argv[1])]
> c = a.show(b)
> print ""
> print ""
> print ""
> print c
>
> Error:
>
> Traceback (most recent call last):
>   File "./python2.py", line 22, in ?
> b = z["%s" % (sys.argv[1])]
> TypeError: string indices must be integers
>
>
> I don't understand why the third one does not work. Thanks for any help!
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
In your code

z = sys.argv[2] which is a string

think you want

b = site[z]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Noobish Syntay Error?

2009-08-06 Thread Dave Angel

Anna - Sophie Maeser wrote:

Hi!
I want to ask you a quick question.. when I type in print '' hello 
world'' and then press enter, it says there is a syntax error... I 
really don't know what im doing wrong. I downloaded python 3.1 and am 
using IDLE with it.. im using mac.
Please help me findt he problem because its a very simple thing and I 
dont know what I am doing wrong..


-Anna




Two syntax errors that I can see.

1) in python 3.1, print is a function, not a statement.  So you need 
parentheses around its argument.
2) You appear to be using two single quotes at each end of  your hello 
world string, You want to either use a single-quote at each end, or 
a double-quote at each end.   This may just because you mistakenly used 
html to compose your email, instead of the preferred text mode.


Try:

print ("hello world")

If your tutorial material is describing Python 2.x, you may not want to 
be learning on Python 3.1, because there are a few of these gotchas.  It 
is possible to install both 2.6 and 3.1, and choose which one you use 
based on what you're working on.


DaveA

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


Re: [Tutor] monitor number of files in a folder

2009-08-06 Thread Sander Sweers
2009/8/6 Dave Angel :
>
> You have to choose your poison.

I prefer no poison. This is exactly what inotiy was made for and
although I never used it there is a python module for it [1]. It would
be great if you can post your experience with it.

Greets
Sander

[1] http://trac.dbzteam.org/pyinotify/wiki
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Looking up a value in a dictionary from user input problem

2009-08-06 Thread chase pettet
I am trying to write a script to work our LVS implementation.  I want to be
able to have  user do something like this "./script SITE SERVER" and have
the script look up the ip value of the site on that server and issue the
command to pull the status from LVS.  I am almost there but for some reason
when I try to pass the site parameter dynamically (the name of the
dictionary) I keep getting errors about value type.  I have two example that
work where the dictionary name is hard coded to to speak in the script, and
the value I want to pull is dynamic using sys.argv[1], and one where I'm
trying to pass the dictionary name and it does not work.  I tried to slim
thse examples down, so hopefully they are helpful:

works #1...

./script.py t

#!/usr/bin/env python
site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
"s2":"10.1.1.5", "s3":"10.1.1.6"}

def runBash(cmd):
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
  out = p.stdout.read().strip()
  return out

class LVS_Site:
  def show(self, site):
showsite = "ipvsadm -L -t %s:443" % (site)
showsiteresult = runBash(showsite)
return showsiteresult

a = LVS_Site()
b = site["%s" % (sys.argv[1])]
c = a.show(b)
print ""
print ""
print ""
print c

works #2...

./script.py t

#!/usr/bin/env python
site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
"s2":"10.1.1.5", "s3":"10.1.1.6"}

def runBash(cmd):
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
  out = p.stdout.read().strip()
  return out

class LVS_Site:
  def show(self, site):
showsite = "ipvsadm -L -t %s:443" % (site)
showsiteresult = runBash(showsite)
return showsiteresult

a = LVS_Site()
z = site
b = z["%s" % (sys.argv[1])]
c = a.show(b)
print ""
print ""
print ""
print c


Not working...

./script.py t site

#!/usr/bin/env python
site = {"l":"10.1.1.1", "t":"10.1.1.2", "x":"10.1.1.3", "s1":"10.1.1.4",
"s2":"10.1.1.5", "s3":"10.1.1.6"}

def runBash(cmd):
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
  out = p.stdout.read().strip()
  return out

class LVS_Site:
  def show(self, site):
showsite = "ipvsadm -L -t %s:443" % (site)
showsiteresult = runBash(showsite)
return showsiteresult

a = LVS_Site()
z = sys.argv[2]
b = b["%s" % (sys.argv[1])]
c = a.show(b)
print ""
print ""
print ""
print c

Error:

Traceback (most recent call last):
  File "./python2.py", line 22, in ?
b = z["%s" % (sys.argv[1])]
TypeError: string indices must be integers


I don't understand why the third one does not work. Thanks for any help!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] monitor number of files in a folder

2009-08-06 Thread Dave Angel

pedro wrote:
On 
2009-08-06 15:49:35 -0400, Wayne  said:





On Thu, Aug 6, 2009 at 2:33 PM, pedro  wrote:


Hi I am rendering image sequences on a basic render farm that I am
building. Once all the files in the sequence have been rendered I 
would like
to make a quicktime of the sequence automatically. The problem I am 
having
is that if one of the computers on the farm is rendering slow the 
quicktime

gets made before all the files are rendered.

The variable below called "theNumberOfImages" is the actual # of images
that have been rendered which is working fine.
The variable below called "theNumberOfFrames" is the total # of 
images that
are supposed to be rendered. What I am trying to do but am not sure 
how is

to say:
As soon as theNumberOfImages is equal to or greater than 
theNumberOfFrames,

render the quicktime.

Here is my very bad solution

if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
else:
os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.sh')



You really just want a  while loop:

while imagecount >= framecount:
time.sleep(60)

# Call script here

I guess that's the easiest way. Probably not the most effective, but 
I'm not
sure if the implementation of an alternate solution would be worth 
the cost.


HTH,
Wayne


On Thu, Aug 6, 2009 at 2:33 PM, 
pedro pan dir=3D"ltr">pedrooconnel=
l...@gmail.com> wrote:class=3D"gmail_quote" styl=
e=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 
0.8ex; =

padding-left: 1ex;">

Hi I am rendering image sequences on a basic render farm that I am 
building=
. Once all the files in the sequence have been rendered I would like 
to mak=
e a quicktime of the sequence automatically. The problem I am having 
is tha=
t if one of the computers on the farm is rendering slow the quicktime 
gets =

made before all the files are rendered.



The variable below called "theNumberOfImages" is the actual 
# of =

images that have been rendered which is working fine.
The variable below called "theNumberOfFrames" is the total 
# of i=
mages that are supposed to be rendered. What I am trying to do but am 
not s=

ure how is to say:
As soon as theNumberOfImages is equal to or greater than 
theNumberOfFrames,=

 render the quicktime.

Here is my very bad solution

if theNumberOfImages <=3D theNumberOfFrames:
 =A0 time.sleep(60)
 =A0 if theNumberOfImages <=3D theNumberOfFrames:
 =A0 =A0 =A0 time.sleep(60)
 =A0 =A0 =A0 if theNumberOfImages <=3D theNumberOfFrames:
 =A0 =A0 =A0 =A0 =A0 time.sleep(60)
else:
 =A0 
os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.s=
h')You really just want a=A0 while 
loop:=A0r>while imagecount >=3D framecount:=A0=A0=A0 
time.sleep(60)#=

 Call script here

I guess that's the easiest way. Probably not the most 
effective, bu=
t I'm not sure if the implementation of an alternate solution 
would be =

worth the cost.HTH,Wayne



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


Hi Wayne, but if I do it that way won't it create an infinite loop if 
the images don't all render?

Pete





(Please post as a text message when using mailing lists like this one.  
All that html junk clutters readability something awful.)



You have to choose your poison.  Your original approach (which you 
called "very bad") had the problem of only waiting 90 seconds max.  
Wayne's has the problem of waiting forever if some rendering aborts.  So 
you need to choose how much of a timeout, and what you want to do when 
you exceed it.   You also have the problem in this code that it's just 
checking variables, rather than calling a function that actually looks 
for the files.  And finally, I think the comparison operator isn't quite 
right (if I understand your two variables anyway).  Perhaps something like:


timeoutcount = 0
while filecount() < framecount and timeoutcount < 10:
   timeoutcount += 1
   time.sleep(30)

if filecount() < framecount:
  print "you lose, because it took longer than ", timeoutcount /2, 
"minutes"

else:
  os.system()


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


Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote:
> 

> 
> As a follow-up question, how do give my modules stored under ./lib access to 
> the data in my ConfigParser object?  (For instance, database connection 
> string, storage path, etc.)
> 
> I guess a global ConfigParser object would work, but that seems wrong.
> 

And yet, to me it seems wrong to have more than one instance of config
data floating around. Instead of using a global you can pass the config
object, or just the appropriate attributes, around to your lib
functions/classes, as necessary -- and keep the flow in your main
script. For example (highly speculative, FWIW),

# app.py
from database.connection import getcursor
from lib.persist import Storage

def main():
confp = ConfigParser()
confp.read(join_relative(__file__, 'config/prefs.ini'))
config = confp.defaults()

curs = getcursor(config[db_connection_string])

...

storage = Storage(config[storage_path])

...

HTH,
Marty

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


Re: [Tutor] monitor number of files in a folder

2009-08-06 Thread pedro

On 2009-08-06 15:49:35 -0400, Wayne  said:




On Thu, Aug 6, 2009 at 2:33 PM, pedro  wrote:


Hi I am rendering image sequences on a basic render farm that I am
building. Once all the files in the sequence have been rendered I would like
to make a quicktime of the sequence automatically. The problem I am having
is that if one of the computers on the farm is rendering slow the quicktime
gets made before all the files are rendered.

The variable below called "theNumberOfImages" is the actual # of images
that have been rendered which is working fine.
The variable below called "theNumberOfFrames" is the total # of images that
are supposed to be rendered. What I am trying to do but am not sure how is
to say:
As soon as theNumberOfImages is equal to or greater than theNumberOfFrames,
render the quicktime.

Here is my very bad solution

if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
else:
os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.sh')



You really just want a  while loop:

while imagecount >= framecount:
time.sleep(60)

# Call script here

I guess that's the easiest way. Probably not the most effective, but I'm not
sure if the implementation of an alternate solution would be worth the cost.

HTH,
Wayne


On Thu, Aug 6, 2009 at 2:33 PM, pedro pedrooconnel=
l...@gmail.com> wrote:

Hi I am rendering image sequences on a basic render farm that I am building=
. Once all the files in the sequence have been rendered I would like to mak=
e a quicktime of the sequence automatically. The problem I am having is tha=
t if one of the computers on the farm is rendering slow the quicktime gets =
made before all the files are rendered.



The variable below called "theNumberOfImages" is the actual # of =
images that have been rendered which is working fine.
The variable below called "theNumberOfFrames" is the total # of i=
mages that are supposed to be rendered. What I am trying to do but am not s=
ure how is to say:
As soon as theNumberOfImages is equal to or greater than theNumberOfFrames,=
 render the quicktime.

Here is my very bad solution

if theNumberOfImages <=3D theNumberOfFrames:
 =A0 time.sleep(60)
 =A0 if theNumberOfImages <=3D theNumberOfFrames:
 =A0 =A0 =A0 time.sleep(60)
 =A0 =A0 =A0 if theNumberOfImages <=3D theNumberOfFrames:
 =A0 =A0 =A0 =A0 =A0 time.sleep(60)
else:
 =A0 os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.s=
h')You really just want a=A0 while loop:=A0while imagecount >=3D framecount:=A0=A0=A0 time.sleep(60)#=
 Call script here

I guess that's the easiest way. Probably not the most effective, bu=
t I'm not sure if the implementation of an alternate solution would be =
worth the cost.HTH,Wayne



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


I got it working but it seems little clunky. If I have a folder with 6 
files in it, python will print out "waiting, still waiting, waiting, 
still waiting..." if I add 3 new file to the folder python prints 
"eight". This is the basic behaviour I want but is there a more 
pythonic way to write this.




import os, time

theFilesAsList = []

for anItem in 
os.listdir('/Volumes/sgtb/lac/comps/Z353_002/renders/Z353_002_comp/Z353_002_comp_v04/2048x1556'):



  if anItem[0] != ".":
   theFilesAsList.append(anItem)
theNumberOfImages = len(theFilesAsList)

while theNumberOfImages <= 8:
   print 'waiting'
   time.sleep(5)
   print 'still waiting'
   time.sleep(5)
   theFilesAsList = []
   for anItem in 
os.listdir('/Volumes/sgtb/lac/comps/Z353_002/renders/Z353_002_comp/Z353_002_comp_v04/2048x1556'):



  if anItem[0] != ".":
   theFilesAsList.append(anItem)
   theNumberOfImages = len(theFilesAsList)
print 'eight'


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


Re: [Tutor] monitor number of files in a folder

2009-08-06 Thread pedro

On 2009-08-06 15:49:35 -0400, Wayne  said:




On Thu, Aug 6, 2009 at 2:33 PM, pedro  wrote:


Hi I am rendering image sequences on a basic render farm that I am
building. Once all the files in the sequence have been rendered I would like
to make a quicktime of the sequence automatically. The problem I am having
is that if one of the computers on the farm is rendering slow the quicktime
gets made before all the files are rendered.

The variable below called "theNumberOfImages" is the actual # of images
that have been rendered which is working fine.
The variable below called "theNumberOfFrames" is the total # of images that
are supposed to be rendered. What I am trying to do but am not sure how is
to say:
As soon as theNumberOfImages is equal to or greater than theNumberOfFrames,
render the quicktime.

Here is my very bad solution

if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
if theNumberOfImages <= theNumberOfFrames:
time.sleep(60)
else:
os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.sh')



You really just want a  while loop:

while imagecount >= framecount:
time.sleep(60)

# Call script here

I guess that's the easiest way. Probably not the most effective, but I'm not
sure if the implementation of an alternate solution would be worth the cost.

HTH,
Wayne


On Thu, Aug 6, 2009 at 2:33 PM, pedro pedrooconnel=
l...@gmail.com> wrote:

Hi I am rendering image sequences on a basic render farm that I am building=
. Once all the files in the sequence have been rendered I would like to mak=
e a quicktime of the sequence automatically. The problem I am having is tha=
t if one of the computers on the farm is rendering slow the quicktime gets =
made before all the files are rendered.



The variable below called "theNumberOfImages" is the actual # of =
images that have been rendered which is working fine.
The variable below called "theNumberOfFrames" is the total # of i=
mages that are supposed to be rendered. What I am trying to do but am not s=
ure how is to say:
As soon as theNumberOfImages is equal to or greater than theNumberOfFrames,=
 render the quicktime.

Here is my very bad solution

if theNumberOfImages <=3D theNumberOfFrames:
 =A0 time.sleep(60)
 =A0 if theNumberOfImages <=3D theNumberOfFrames:
 =A0 =A0 =A0 time.sleep(60)
 =A0 =A0 =A0 if theNumberOfImages <=3D theNumberOfFrames:
 =A0 =A0 =A0 =A0 =A0 time.sleep(60)
else:
 =A0 os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.s=
h')You really just want a=A0 while loop:=A0while imagecount >=3D framecount:=A0=A0=A0 time.sleep(60)#=
 Call script here

I guess that's the easiest way. Probably not the most effective, bu=
t I'm not sure if the implementation of an alternate solution would be =
worth the cost.HTH,Wayne



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


Hi Wayne, but if I do it that way won't it create an infinite loop if 
the images don't all render?

Pete


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


[Tutor] Fwd: Noobish Syntay Error?

2009-08-06 Thread Wayne
Forgot reply-all

-- Forwarded message --
From: Wayne 
Date: Thu, Aug 6, 2009 at 3:32 PM
Subject: Re: [Tutor] Noobish Syntay Error?
To: Anna - Sophie Maeser 


On Thu, Aug 6, 2009 at 2:08 PM, Anna - Sophie Maeser <
annasop...@dautzenberg.org> wrote:

> Hi!
> I want to ask you a quick question.. when I type in print '' hello world''
> and then press enter, it says there is a syntax error... I really don't know
> what im doing wrong. I downloaded python 3.1


There's your problem - downgrade to python 2.6 or type print('hello world')

HTH,
Wayne



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Noobish Syntay Error?

2009-08-06 Thread Anna - Sophie Maeser

Hi!
I want to ask you a quick question.. when I type in print '' hello  
world'' and then press enter, it says there is a syntax error... I  
really don't know what im doing wrong. I downloaded python 3.1 and am  
using IDLE with it.. im using mac.
Please help me findt he problem because its a very simple thing and I  
dont know what I am doing wrong..


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


Re: [Tutor] easy way to populate a dict with functions

2009-08-06 Thread bob gailer

Albert-Jan Roskam wrote:

Hi Bob,

Very neat solution, thanks a lot! I didn't know the inspect module, but it's just what's needed here. Cool! 


Great.

Regarding the ordering of functions in the list - variable names in 
namespaces (such as modules) are stored in dictionaries. Any ordering is 
lost in this process. Why is order important to you here?


There are other things that could be said about your program and my 
revision.


1 - it is better to have functions return values and have the main 
program decide whether to print them or take some other action. (Also 
note you were not consistent - foo returns the others print!)


2 - since the list contains the function names as well as references to 
the functions you could present the names to the user. You could even 
ask the user to enter the first letter(s) of the names instead of a number.


3 - with a slight enhancement to things you can preserve the order:

#  commands.py ---
cmds = [] 


def collect(func):
 'a "decorator" that adds each function to the cmds list'
 cmds.append((func.__name__, func))

@collect
def foo (a):
return "foo" * a

@collect
def bletch (q):
for i in range(20):
  return i * q

@collect
def stilton (n):
return "yes sir, " * n

@collect
def romans (z):
return "what have the romans really done for us?\n" * z

#  end code ---

#  main.py ---
import commands
cmds = commands.cmds

# etc.

--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] monitor number of files in a folder

2009-08-06 Thread Wayne
On Thu, Aug 6, 2009 at 2:33 PM, pedro  wrote:

> Hi I am rendering image sequences on a basic render farm that I am
> building. Once all the files in the sequence have been rendered I would like
> to make a quicktime of the sequence automatically. The problem I am having
> is that if one of the computers on the farm is rendering slow the quicktime
> gets made before all the files are rendered.
>
> The variable below called "theNumberOfImages" is the actual # of images
> that have been rendered which is working fine.
> The variable below called "theNumberOfFrames" is the total # of images that
> are supposed to be rendered. What I am trying to do but am not sure how is
> to say:
> As soon as theNumberOfImages is equal to or greater than theNumberOfFrames,
> render the quicktime.
>
> Here is my very bad solution
>
> if theNumberOfImages <= theNumberOfFrames:
>   time.sleep(60)
>   if theNumberOfImages <= theNumberOfFrames:
>   time.sleep(60)
>   if theNumberOfImages <= theNumberOfFrames:
>   time.sleep(60)
> else:
>   os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.sh')


You really just want a  while loop:

while imagecount >= framecount:
time.sleep(60)

# Call script here

I guess that's the easiest way. Probably not the most effective, but I'm not
sure if the implementation of an alternate solution would be worth the cost.

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


Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote:
> 
> 
> 
>>> What is the recommended way to configure my application find the various 
>> database and/or configuration files it needs?
>>
>> Recommemded by whom? A lot depends on the OS. Apple for example have one set 
>> of 
>> recommendations for MacOS, Windows has another and Linux has several to 
>> choose 
>> from!
>>
> 
> 
> Thank you good point.
> 
> Planning on using a ConfigParser based .ini file located in the ./config 
> folder.
> 
>>> For instance my folder layout:
>>>
>>> /path_to_app/app.py
>>> /path_to_app/lib/
>>> /path_to_app/database/
>>> /path_to_app/config/
>>> /path_to_app/photos
>>>
>>>  and so on.  I would like to make an .ini in the config folder 
>> Seems fair enough, however on a Unix system you should also consider 
>> allowing 
>> the user to have their own personalised version in their home directory. 
>> Thus at 
>> startup you get the current user ID / home directory and look for a suitable 
>> config file. If it exists read it, if not read the default one in your 
>> config 
>> directory.
>>
>>> 1) How does my main app file find the config file in the first place?
>> Generally use a relative path so normally your app will run from its home 
>> folder 
>> so you can look in ./config. You might also set a system environment 
>> variable - 
>> for example the CLASSPATH or PYTHONPATH variables, or the ORACLE_HOME used 
>> by 
>> Oracle for their database. If the environment var is not set then look in 
>> ./config
>>
> 
> Assuming the application could be invoked in odd ways that may alter the 
> notion of the current working directory, how do I unambiguously find the 
> absolute path to the current python source file?  (So I can load the nearby 
> .ini)

I use a helper function that calculates the absolute path of my app
script, then I am able to os.path.join relative elements to my heart's
content. I haven't had a problem with this approach so far, which of
course doesn't mean it's the right way, or even a correct implementation
for that matter.

Something like this ...

# lib/mypaths.py
# --

import os

def script_path(base):
return os.path.realpath(os.path.abspath(base))

def script_dir(base):
return os.path.dirname(script_path(base))

def join_relative(base, path):
return os.path.join(script_dir(base), path)

# app.py
# --

...

from lib.mypaths import join_relative
print join_relative(__file__, 'config/prefs.ini')

# this may work when calling from
# other modules, I suppose (untested)

import sys
print join_relative(sys.argv[0], 'config/prefs.ini')

...


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


Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Che M


> Start a CMD window and run the python command by typing the command
> at the DOS prompt.
> 
> eg
> 
> C:\Windows> python some\path\to\myscript.py
> 
> 
> That way you will still see the error message after the
> program finishes.

Or what about using IDLE?  



_
Express your personality in color! Preview and select themes for Hotmail®. 
http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=PID23391::T:WLMTAGL:ON:WL:en-US:WM_HYGN_express:082009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] monitor number of files in a folder

2009-08-06 Thread pedro
Hi I am rendering image sequences on a basic render farm that I am 
building. Once all the files in the sequence have been rendered I would 
like to make a quicktime of the sequence automatically. The problem I 
am having is that if one of the computers on the farm is rendering slow 
the quicktime gets made before all the files are rendered.


The variable below called "theNumberOfImages" is the actual # of images 
that have been rendered which is working fine.
The variable below called "theNumberOfFrames" is the total # of images 
that are supposed to be rendered. What I am trying to do but am not 
sure how is to say:
As soon as theNumberOfImages is equal to or greater than 
theNumberOfFrames, render the quicktime.


Here is my very bad solution

if theNumberOfImages <= theNumberOfFrames:
   time.sleep(60)
   if theNumberOfImages <= theNumberOfFrames:
   time.sleep(60)
   if theNumberOfImages <= theNumberOfFrames:
   time.sleep(60)
else:
   os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.sh')


An help would be greatly appreciated
Pete


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


Re: [Tutor] easy way to populate a dict with functions

2009-08-06 Thread Albert-Jan Roskam
...Still one more question:
cmds = inspect.getmembers(commands, inspect.isfunction)
print cmds
#will generate
[('bletch', ), ('foo', ), ('romans', ), ('stilton', 
)]

This looks okay, but the order in which the functions appear in the module 
(commands.py) is different:
foo, bletch, stilton, romans

Do you know why?

Cheers again,
Albert-Jan

--- On Thu, 8/6/09, bob gailer  wrote:

> From: bob gailer 
> Subject: RE:  [Tutor] easy way to populate a dict with functions
> To: fo...@yahoo.com
> Cc: "tutorpythonmailinglist Python" 
> Date: Thursday, August 6, 2009, 7:28 PM
> Please start a new email when
> starting a new topic. Otherwise it gets linked to the
> previous one in email clients that follow threads!
> 
> To avoid that here I am responding in a new email. Also
> fixed spelling in subject.
> 
> Albert-Jan Roskam wrote:
> > Hi,
> > 
> > I was playing with the code below, and I was wondering
> if there was a way to populate the dictionary called
> 'commands' (in the function 'check_command()').
> > 
> > Suppose I would add another function, which I would
> also like to store as a value in 'commands', could it simply
> be programmed, or would every update/addition require the
> definition of the dictionary to be extended?
> > It would be most desirable if one could simply add
> another function without there being the need to touch any
> of the other code. 
> > 
> >   
> Here's how I'd do it. Others may have other solutions.
> 
> Put the command functions in a separate module, e.g.,
> commands.py:
> #  code ---
> def foo (a):
>  return "foo" * a
> 
> def bletch (q):
>  for i in range(20):
>    print i * q
> 
> def stilton (n):
>  print "yes sir, " * n
> 
> def romans (z):
>  print "what have the romans really done for us?\n" * z
> #  end code ---
> 
> Put the "main" program (in another module) e.g., main.py:
> 
> #  code ---
> import commands
> import inspect
> cmds = inspect.getmembers(commands, inspect.isfunction)
> num_cmds = len(cmds)
> option_list = "|".join(str(c) for c in range(1,
> num_cmds+1))
> prompt = "choose an option [%s]: " % option_list
> 
> def check_command():
>  while True:
>    select = raw_input(prompt)
>    try:
>      command = cmds[int(select)][1]
>    except ValueError:
>      print "non-numeric option 
>    (%s)" % select
>    except IndexError:
>      print "option out of range (%s)" %
> select
>    else:
>      check_parameter(command)
>      break
> 
> def check_parameter(command):
>  while True:
>    parameter = raw_input("choose a parameter
> [integer]: ")
>    if parameter.isdigit():
>      command(int(parameter))
>      break
>    else:
>      print "illegal parameter (%s)" %
> parameter
> 
> check_command()
> #  end code ---
> 
> cmds is a list similar to:
>  [('bletch', ),
>  ('foo', ),
>  ('romans', ),
>  ('stilton', )]
> 
> -- Bob Gailer
> Chapel Hill NC
> 919-636-4239
> 
> 


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


Re: [Tutor] easy way to populate a dict with functions

2009-08-06 Thread Albert-Jan Roskam
Hi Bob,

Very neat solution, thanks a lot! I didn't know the inspect module, but it's 
just what's needed here. Cool! And sorry about not starting a new mail. I'll 
keep it in mind for next time.

Best wishes,
Albert-Jan 

--- On Thu, 8/6/09, bob gailer  wrote:

> From: bob gailer 
> Subject: RE:  [Tutor] easy way to populate a dict with functions
> To: fo...@yahoo.com
> Cc: "tutorpythonmailinglist Python" 
> Date: Thursday, August 6, 2009, 7:28 PM
> Please start a new email when
> starting a new topic. Otherwise it gets linked to the
> previous one in email clients that follow threads!
> 
> To avoid that here I am responding in a new email. Also
> fixed spelling in subject.
> 
> Albert-Jan Roskam wrote:
> > Hi,
> > 
> > I was playing with the code below, and I was wondering
> if there was a way to populate the dictionary called
> 'commands' (in the function 'check_command()').
> > 
> > Suppose I would add another function, which I would
> also like to store as a value in 'commands', could it simply
> be programmed, or would every update/addition require the
> definition of the dictionary to be extended?
> > It would be most desirable if one could simply add
> another function without there being the need to touch any
> of the other code. 
> > 
> >   
> Here's how I'd do it. Others may have other solutions.
> 
> Put the command functions in a separate module, e.g.,
> commands.py:
> #  code ---
> def foo (a):
>  return "foo" * a
> 
> def bletch (q):
>  for i in range(20):
>    print i * q
> 
> def stilton (n):
>  print "yes sir, " * n
> 
> def romans (z):
>  print "what have the romans really done for us?\n" * z
> #  end code ---
> 
> Put the "main" program (in another module) e.g., main.py:
> 
> #  code ---
> import commands
> import inspect
> cmds = inspect.getmembers(commands, inspect.isfunction)
> num_cmds = len(cmds)
> option_list = "|".join(str(c) for c in range(1,
> num_cmds+1))
> prompt = "choose an option [%s]: " % option_list
> 
> def check_command():
>  while True:
>    select = raw_input(prompt)
>    try:
>      command = cmds[int(select)][1]
>    except ValueError:
>      print "non-numeric option 
>    (%s)" % select
>    except IndexError:
>      print "option out of range (%s)" %
> select
>    else:
>      check_parameter(command)
>      break
> 
> def check_parameter(command):
>  while True:
>    parameter = raw_input("choose a parameter
> [integer]: ")
>    if parameter.isdigit():
>      command(int(parameter))
>      break
>    else:
>      print "illegal parameter (%s)" %
> parameter
> 
> check_command()
> #  end code ---
> 
> cmds is a list similar to:
>  [('bletch', ),
>  ('foo', ),
>  ('romans', ),
>  ('stilton', )]
> 
> -- Bob Gailer
> Chapel Hill NC
> 919-636-4239
> 
> 


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


Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Alan Gauld

"Joshua Harper"  wrote


Ok, so I am trying to learn python, and I am reading many tutorial type


If you are just learning Python downgrade from 3.1 to v2.6.

Most tutorials are not up to 3.1 yet and there are many differences.
v3.1 was a big change to the language.

eg. The following code is for v2, it needs changing for v3:


x = input("Please enter a number: ")


x = int( input("Please enter a number: ") )


print "The square of that number is


print ( "The square of that number is )


I save this as a .py and Open With>python.exe. OK, so that gives me the
terminal ansking me to enter a number, I enter a number and click enter 
and

then it prints in like half a nanosecond and the cmd line window closes.


Others have answered this.
You really need an option though that will display the error message that
I suspect you are getting...

Start a CMD window and run the python command by typing the command
at the DOS prompt.

eg

C:\Windows> python some\path\to\myscript.py


That way you will still see the error message after the
program finishes.

HTH,

BTW My tutorial is nearly half way to being converted to v3 now,
you might find it useful if you don;t want to revert to 2.6. But personally
I'd go back!

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p/ 



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


Re: [Tutor] easy way to populate a dict with functions

2009-08-06 Thread bob gailer
Please start a new email when starting a new topic. Otherwise it gets 
linked to the previous one in email clients that follow threads!


To avoid that here I am responding in a new email. Also fixed spelling 
in subject.


Albert-Jan Roskam wrote:

Hi,

I was playing with the code below, and I was wondering if there was a way to 
populate the dictionary called 'commands' (in the function 'check_command()').

Suppose I would add another function, which I would also like to store as a 
value in 'commands', could it simply be programmed, or would every 
update/addition require the definition of the dictionary to be extended?
It would be most desirable if one could simply add another function without there being the need to touch any of the other code. 



  

Here's how I'd do it. Others may have other solutions.

Put the command functions in a separate module, e.g., commands.py:
#  code ---
def foo (a):
 return "foo" * a

def bletch (q):
 for i in range(20):
   print i * q

def stilton (n):
 print "yes sir, " * n

def romans (z):
 print "what have the romans really done for us?\n" * z
#  end code ---

Put the "main" program (in another module) e.g., main.py:

#  code ---
import commands
import inspect
cmds = inspect.getmembers(commands, inspect.isfunction)
num_cmds = len(cmds)
option_list = "|".join(str(c) for c in range(1, num_cmds+1))
prompt = "choose an option [%s]: " % option_list

def check_command():
 while True:
   select = raw_input(prompt)
   try:
 command = cmds[int(select)][1]
   except ValueError:
 print "non-numeric option (%s)" % select
   except IndexError:
 print "option out of range (%s)" % select
   else:
 check_parameter(command)
 break

def check_parameter(command):
 while True:
   parameter = raw_input("choose a parameter [integer]: ")
   if parameter.isdigit():
 command(int(parameter))
 break
   else:
 print "illegal parameter (%s)" % parameter

check_command()
#  end code ---

cmds is a list similar to:
 [('bletch', ),
 ('foo', ),
 ('romans', ),
 ('stilton', )]

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

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


[Tutor] easy way to pupulate a dict with functions

2009-08-06 Thread Albert-Jan Roskam
Hi,

I was playing with the code below, and I was wondering if there was a way to 
populate the dictionary called 'commands' (in the function 'check_command()').

Suppose I would add another function, which I would also like to store as a 
value in 'commands', could it simply be programmed, or would every 
update/addition require the definition of the dictionary to be extended?
It would be most desirable if one could simply add another function without 
there being the need to touch any of the other code. 

Cheers!!
Albert-Jan()

def foo (a):
return "foo" * a

def bletch (q):
for i in range(20):
print i * q

def stilton (n):
print "yes sir, " * n

def romans (z):
print "what have the romans really done for us?\n" * z

def check_command():
commands = {'1': foo, '2': bletch, '3': stilton, '4': romans}
while True:
select = raw_input("choose an option [%s]: " % 
"|".join(sorted(commands.keys(
if select in commands.keys():
check_parameter(commands, select)
break
else:
print "illegal option (%s)" % select

def check_parameter(commands, select):
while True:
parameter = raw_input("choose a parameter [integer]: ")
if parameter.isdigit():
commands[select](int(parameter))
break
else:
print "illegal parameter (%s)" % parameter

check_command()



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


Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Dave Angel

Michael Connors wrote:

2009/8/6 Joshua Harper 

  

Ok, so I am trying to learn python, and I am reading many tutorial type
things and I am kind of stuck with implementing some of the code... so for
example the tutorial says "*To get the examples working properly, write
the programs in a text file and then run that with the interpreter*"
Alright...simple enough so I wirte the example program:

x = input("Please enter a number: ")
print "The square of that number is

I save this as a .py and Open With>python.exe. OK, so that gives me the
terminal ansking me to enter a number, I enter a number and click enter and
then it prints in like half a nanosecond and the cmd line window closes. I
want to know how to have the window stay open so that, in future scripts I
may be able to actually see what was printed. I talked to my friend and he
said that he has the same problem...anybody?...help???




It closes because it is finished.

If you want to see the result, you could either:

- Place another input("") after the print statement.
- Run the program from the command prompt (in which case you will probably
need to set the path)

  

Michael is correct, but I'd like to expand on the answer.

In Windows, there are two kinds of applications, console apps and gui 
apps.  A console app uses stdin and stdout (character mode, like input 
and print).  A gui app has buttons, menus, and dialog boxes.  Console 
apps are much easier to write and debug, they tend to run faster, and 
tutorials always start there.


A console app can be run from an Explorer shortcut, or from the context 
menu as you're doing, but you're missing a lot.  As you've already 
noticed, the console is deleted immediately after the program 
terminates.  So you can put an extrainput("Press OK to finish")   at 
the end of your code.  But for various reasons (eg. bugs) your program 
may never reach that line.  And if it doesn't, any error messages will 
also vanish when the console does.  While there are workarounds for 
this, the real answer is to learn to use a command prompt.  At least 
until a program is bug-free.


A "command prompt"  (aka "Dos Box", or console, or shell) can be started 
from the "Run" command on the start menu --  just type   "Cmd"  as the 
program to run.  There's also a shortcut called "Command Prompt" in 
Start->Accesssories.



The default installation on Windows sets up a file association for both 
.py and .pyw files, so you should be able to just type   example.py
at the command prompt to run the program.  The command prompt window
will scroll to hold more input than would otherwise fit on screen.  And 
you can copy & paste from and to a command prompt, though it's tricky 
(another discussion).


You may want to create a few batch files to make your life at the 
command prompt a bit easier.  For example, the path to the python 
interpreter is not normally added to the PATH variable, and I don't 
think it should.  So if you want to run Python.exe explicitly, it helps 
to make a batch file to make that easier.  We can help with that as well.



When you run the program from the command prompt, the print output stays 
there till you either close the command prompt, or run enough other 
stuff that it scrolls off the top end of the buffer.


DaveA

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


Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Robert Berman


On Thu, 2009-08-06 at 03:44 -0400, Joshua Harper wrote:

> Ok, so I am trying to learn python, and I am reading many tutorial
> type things and I am kind of stuck with implementing some of the
> code... so for example the tutorial says "To get the examples working
> properly, write the programs in a text file and then run that with the
> interpreter" Alright...simple enough so I wirte the example program:
> 
> 
> x = input("Please enter a number: ")
> print "The square of that number is

raw_input('Press Enter to end>>')

> I save this as a .py and Open With>python.exe. OK, so that gives me
> the terminal ansking me to enter a number, I enter a number and click
> enter and then it prints in like half a nanosecond and the cmd line
> window closes. I want to know how to have the window stay open so
> that, in future scripts I may be able to actually see what was
> printed. I talked to my friend and he said that he has the same
> problem...anybody?...help???
> 
> -- 
> - JH


Hope this helps,

Robert

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


Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Michael Connors
2009/8/6 Joshua Harper 

> Ok, so I am trying to learn python, and I am reading many tutorial type
> things and I am kind of stuck with implementing some of the code... so for
> example the tutorial says "*To get the examples working properly, write
> the programs in a text file and then run that with the interpreter*"
> Alright...simple enough so I wirte the example program:
>
> x = input("Please enter a number: ")
> print "The square of that number is
>
> I save this as a .py and Open With>python.exe. OK, so that gives me the
> terminal ansking me to enter a number, I enter a number and click enter and
> then it prints in like half a nanosecond and the cmd line window closes. I
> want to know how to have the window stay open so that, in future scripts I
> may be able to actually see what was printed. I talked to my friend and he
> said that he has the same problem...anybody?...help???
>
>
It closes because it is finished.

If you want to see the result, you could either:

- Place another input("") after the print statement.
- Run the program from the command prompt (in which case you will probably
need to set the path)

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


[Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Joshua Harper
Ok, so I am trying to learn python, and I am reading many tutorial type
things and I am kind of stuck with implementing some of the code... so for
example the tutorial says "*To get the examples working properly, write the
programs in a text file and then run that with the interpreter*"
Alright...simple enough so I wirte the example program:

x = input("Please enter a number: ")
print "The square of that number is

I save this as a .py and Open With>python.exe. OK, so that gives me the
terminal ansking me to enter a number, I enter a number and click enter and
then it prints in like half a nanosecond and the cmd line window closes. I
want to know how to have the window stay open so that, in future scripts I
may be able to actually see what was printed. I talked to my friend and he
said that he has the same problem...anybody?...help???

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