Re: [Tutor] help with my python app

2005-05-17 Thread Alan G
Hi James,

I can't answer your question because I don't know anything
about pygame, but your code would look a lot better if you
wrote a function (handleKeyEvent() say?) to avoid repeating
all that code. One of the big advantages of using functions
- aside from saving typing effort - is that they make the
code more readable by replacing a lot of detail with a
short descriptive phrase(the functions name). The other
advantage is that if the code has to be fixed you only
change it in one place so there's less chance of you
accidentaly missing out one of the event handlers.

If the code is slightly diffeent each time - although from
a quick look this doesn't seem to be the case here - you
can parameterise the function so you can pass in either the
changing values or some flag to indicate which variant you
need. It's all part of helping us to see the wood instead of
the trees...

HTH

Alan G.

- Original Message - 
From: "james middendorff" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, May 17, 2005 4:40 AM
Subject: [Tutor] help with my python app


> Hello, I would like to be able to use the arrow keys
> to control a remote control car, which I can do but
> only one key at a time. I would like to press the up
> key, then while it is moving forward, press the left
> or right key to turn while it is moving forward? I am
> sure there are probably better ways to write the code,
> I am still learning all of this. Also if this
> indention is off I am including the file
> thanks
>
> #!/usr/bin/python
> import parallel
> import pygame
> from pygame.locals import *
>
> p=parallel.Parallel()
> p.setData(0)
>
>
>
>
>
>
>
> def main():
> # Initialise screen
> pygame.init()
> screen = pygame.display.set_mode((640, 480))
> pygame.display.set_caption("James' custom RC
> Car Application")
>
> # Fill background
> background = pygame.Surface(screen.get_size())
> background = background.convert()
> background.fill((250, 250, 250))
>
> # Display some text
> font = pygame.font.Font(None, 36)
> text = font.render("Which Way? ", 1, (10, 10,
> 10))
> textpos = text.get_rect()
> textpos.centerx =
> background.get_rect().centerx
> background.blit(text, textpos)
>
> # Blit everything to the screen
> screen.blit(background, (0, 0))
> pygame.display.flip()
>
> # Event loop
> while 1:
> for event in pygame.event.get():
> if event.type == QUIT:
> return
> elif event.type == KEYDOWN:
> if event.key == K_UP:
> background.fill((250, 250, 250))
> font = pygame.font.Font(None, 36)
> text = font.render("Forward", 1, (10, 10,
> 10))
> textpos = text.get_rect()
> textpos.centerx =
> background.get_rect().centerx
> background.blit(text, textpos)
> screen.blit(background, (0, 0))
> pygame.display.flip()
> screen.blit(background, (0, 0))
> pygame.display.flip()
> p.setData(1)
>
>
> if event.key == K_DOWN:
> background.fill((250, 250, 250))
> font =
> pygame.font.Font(None, 36)
> text =
> font.render("Reverse", 1, (10, 10, 10))
> textpos =
> text.get_rect()
>
> textpos.centerx = background.get_rect().centerx
>
> background.blit(text, textpos)
>
> screen.blit(background, (0, 0))
>
> pygame.display.flip()
>
> screen.blit(background, (0, 0))
>
> pygame.display.flip()
> p.setData(2)
>
>
> if event.key == K_LEFT:
> background.fill((250, 250, 250))
> font =
> pygame.font.Font(None, 36)
> text =
> font.render("LEFT", 1, (10, 10, 10))
> textpos =
> text.get_rect()
> textpos.centerx =
> background.get_rect().centerx
> background.blit(text,
> textpos)
>
> screen.blit(background, (0, 0))
> pygame.display.flip()
>
> screen.blit(background, (0, 0))
> pygame.display.flip()
> p.setData(8)
>
>
> if event.key == K_RIGHT:
> background.fill((250, 250, 250))
> font =
> pygame.font.Font(None, 36)
> text =
> font.render("RIGHT", 1, (10, 10, 10))
> textpos =
> text.get_rect()
>
> textpos.centerx = background.get_rect().centerx
>
> background.blit(text, textpos)
>
> screen.blit(background, (0, 0))
>
> pygame.display.flip()
>
> screen.blit(background, (0, 0))
>
> pygame.display.flip()
> p.setData(4)
>
>
>
> elif event.type == KEYUP:
> if event.key == K_UP:
> background.fill((250, 250, 250))
> font =
> pygame.font.Font(None, 36)
> text =
> font.render("

Re: [Tutor] YATENJoe

2005-05-17 Thread Andrei
Joseph Quigley  gmail.com> writes:

> I want to make a text editor. I know that there are hundreds out there,
> but practice makes perfect, and I need the practice. My problem is
> that I have no idea how to make one. I've tried a little already by
> defining line functions:def line1():l1 =
> raw_input("")

If you intend to make a text editor (something which allows the user to browse
through the text and manipulate it at will) using just raw_input and print, I
think you've set yourself an impossible task. For a console editor you should
probably look at curses (http://www.amk.ca/python/howto/curses/) - which don't
work on Windows, so you'll probably need this:
http://adamv.com/dev/python/curses/ (but according to the site it's 
incomplete). 

It's probably better to select a GUI toolkit which has an editor widget and
build your editor on that. Tkinter and wxPython both offer this, with wxPython
including a wrapper of the excellent Scintilla control (it has syntax
highlighting, word wrapping, support for non-monospaced fonts, etc.). You could
even write a webbased editor using the text entry widget provided by browsers
(crappy as it may be), even that would be better than hand-coding your own
editor widget.

> line2()Of course, this only allows for 2 lines. What's the trick to an
> infinite number of lines?

lines = []
while True:
lines.append(raw_input(''))

(But that offers no way to e.g. save and continue.)

> YATENJoe"? I'm still a newbie to python (actually OOP programming in
> general!) so I can't have a lot of complicated stuff thrown in my
> face.

Text editors are IMO not applications suitable for learning vanilla Python, or
OOP for that matter. Text editors are used as example applications in the RAD
IDE world (VB, Delphi and such) because in those environments a text editor is
literally three clicks away (click on memo component, click on form, click on
run). Vanilla Python has no GUI, so no memo component - hence my recommendation
for Tkinter or wxPython. PythonCard and Boa provide an experience somewhat
similar to commercial RAD IDE's if that's what you're looking for.

> I thought of a function that would define a function for me. Is this
> possible? If it is how would I do it? If it possible, here's my

Having one function for each line is a bad idea whether you code it by hand or
automatically (yes, it would be possible, but not something you should want to
do). A line of text is a piece of *data* similar to the line before it and the
line after it. 
A function implements certain behavior. Having the same behavior (raw_input)
implemented separately for each line is an extremely wasteful way of
programming. Use data containers (like lists) for storing data and use a single
function for manipulating any item (line) in such a data structure. E.g. let's
say you have 5 lines of text and you want to uppercase them all. Your way would
be to create 5 separate functions (or 1000 if there are more lines) for each
of the lines and call each of those. A better way would be to have a single
function and call that repeatedly telling it on which line to operate.

I would suggest that you learn a bit more about Python's facilities before
embarking on an ambitious project :) - you won't get very far without knowing
how to use lists and dictionaries.

Yours,

Andrei

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


[Tutor] Save data 'over SSH'

2005-05-17 Thread Olli Rajala
Hi guys (and gals too!)

I'm writing a program where I would need to write the output finally
to the computer I can access with SSH/SFTP/SCP. So, is there any
'pythonish' way to do it, or do I have to use os.system() or something
similar? I can save it temporarily to the computer the program is
running on, if that matters. Oh, the program is a cgi-script running
on Apache2 and it's running on my own computer so if I need to install
some additional modules, it is possible.

Thanks in advance!
-- 
Olli Rajala <><
Tampere, Finland
http://www.students.tut.fi/~rajala37/

"In theory, Theory and Practice should be
the same. But in practice, they aren't."
- Murphy's Proverbs
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Linux variable to Python

2005-05-17 Thread Terry Carroll
On Fri, 13 May 2005, Alberto Troiano wrote:

> To explain for those who doesn't know:
> The first line creates a variable named "fec" with the value cam(a Linux 
> function returning year month day hour minute second).jpg
> The second show the value of "fec"
> The third moves hola.txt to the directory grabacion and puts the "fec" value 
> as the new name for the file

I do something similar in a pure python program:


# get to temporary directory
(_year, _mon, _day, _hour, _min, _sec, _none, _none, _none)=time.localtime()
temp_dir = "D%4d-%02d-%02d-%02d%02d%02d" % (_year, _mon, _day, _hour, _min, 
_sec)
os.mkdir(temp_dir)
os.chdir(temp_dir)

This creates a directory in the form D-MM-DD-HHMMSS (for example, at 
6:10:08 PM on May 12, 2005, the directory is named D2005-05-12-181008), 
and then makes it the current directory.

You could probably do the same with minimal tweaking.

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


Re: [Tutor] Opinions about this GIS script

2005-05-17 Thread Andrei
Ron Phillips  engineer.co.summit.oh.us> writes:

> The script produces expected results, but if anyone is so inclined, I'd
appreciate review/evaluation/critique of the 'pythonism' of the script. 

I haven't read it from A to Z, but it looks OK. Some minor things:

- string formatting, e.g.:
out+= 'Attribute: '+field+" => "+str(self.fileAttributes[field])+'\n'
I'd prefer seeing a format string. "Attribute: %s => %d\n" % (field,
self.fileAttributes[field]) - I'm guessing at types here, with file as string
and attrib as integer.

- lists of strings and ''.join instead of +, e.g.:
I'd favor making 'out' a list of strings and building the result at the end,
using "\n".join(out).

- long functions/loops: there are two parse functions which don't fit on my
screen. Perhaps they can be split in smaller parts. There's some duplicate code
in the two large (and also the third smaller) parse functions, indicating that
splitting in smaller pieces should be possible and would also remove the
duplicate code.

- There's a lot of "struct.unpack('>i',indexfile.read(4))[0]" and similar lines.
A file class which would wrap this stuff and offer a nice interface with methods
like ReadInt, ReadDouble would clear it up a bit.

- "Private function" in the comment of __newdemo. I'd remove it, since the
double underscore already documents this. 

Yours,

Andrei

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


[Tutor] Removing lines in string-table

2005-05-17 Thread Olli Rajala
Okay,
I have a string table (don't recall the right word used in Python
right now) and would like to remove every 'cell' that contains a
string '_thumb.jpg'. There are 1-> digits before the string if that
matters. I made a for-loop that does what I want to:

for line in fileNames:
if line[-10:] == '_thumb.jpg':
fileNames.remove(line)

But I really doubt that it's not the best way to do this. So, any
comments are really appreciated.

Back to coding...
-- 
Olli Rajala <><
Tampere, Finland
http://www.students.tut.fi/~rajala37/

"In theory, Theory and Practice should be
the same. But in practice, they aren't."
- Murphy's Proverbs
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creation of a module

2005-05-17 Thread Cedric BRINER
Hi Alan
> Hi Cedric,
> 
> Reading through this I can't help but think you are going to
> a lot of trouble to make things very complicated for yourself
> - and for anyone else who has to work on your code. The
> Python module system is very simple and helpful in tracking
> down where the various things live. You can see by the
> prefix name which package/file provides which service.
> It appears that you are trying to hide that information?
> 
> Is there a special reason why you are trying to introduce
> this kind of obfuscation?
> 
> > > > {a,b,c}.py contains respecetively classA,classB,classC more some
> unittest
> > > > and bunch.py will contains some usefull function using the
> class{A,B,C}
> > > >
> > > > I'd like that when I import MyModule (`import MyModule')OB
> > > >  I'll see from it:
> > > > MyModule.classA
> > > > .classB
> > > > .classC
> > > > .
> > > > .
> > > > ...
> > > > without seeing MyModule.{a,b,c}
> 
> Why do you want to conceal the information about what lives inside
> the package? How will users be able to debug the package? If you
> hide a,b and c you will make it harder to do things like
I thought that it will be more convenient. But as I can read from your email: 
it seems a really __not_so_good__ idea .
> 
> >>> dir(MyModule)
> >>> dir (MyModule.a)
> 
> etc to explore the structure and find the code.
never done such kind of things.
> 
> > I've done it. But is it normal that I'see also the filename
> 
> Actually you don;t see the filename you see the sub moduile names.
> a.py becomes a module called a within your package.
> 
> > the idea was to automate the :
> > from MyModule.a import classA
> > from MyModule.b import classB
> > from MyModule.c import classC
> 
> What is the advantage - apart from a minimal amount of typing?
> You still need to maintain a list of the class/module mappings.
no the idea was to give a prefix to all my files depending on the way I'd like 
to import them. In fact, my files are named class_foo.py and the class inside 
this file is named CFoo. 

> > with a loop
> > 
> > lclassname=['classA', 'classB', 'classC']
> > #in the future I can even automate the creation of classname list
> > for classname in lclassname:
> >   #filename='a', classname='classA'
> >   filename=classname.replace('class','').lower()
> 
> Maybe you should use a dictionary as Kent suggested:
> 
> classes = {'classA': 'a',
>'classB': 'b',
>'classC : 'c'
>   }
> 
> filename = classes[classname]
> 
> >   #from filename import classname
> >   module=__import__(filename, gloabls(), locals(), [classname])
> >   classDefinition=getattr(module,classname)
> >   assign(classname,classDefinition)
> > 
> 
> But this is a lot of work to sabve a very small amount of typing and
> could slow down your program initialisation significantly.
> 
> > In this way, when I'll do an
> > import FWobs
> > I'll get:
> > MyModule.classA
> > .classB
> > .classC
> > .
> > .
> 
> It looks as if all you really want to do is avoid having the
> sub-module names visible when you import the package. As I
> explained above I think thats a fundamentally bad idea.
Good, I'll follow your recommendation

> If you do just want to export a single set of services from a
> single import it would be much simpler to just put them all
> in a single module! And then you can hide the exposed names
> using the Python naming convention of prefixing with '_'
> or ' __'.
> 
> Of course if its a very large set of services a package
> is better, but then you probably should expose the sub modules
> too. NAmespaces are one of Pythons best features - they are
> simple to use and very effective both in controlling program
> structure and in aiding debugging, its probabnly best to use
> them as intended rather than trying to force them to work
> differently.
> 
> All IMHO of course! :-)
> 
> Alan G

thanks for your time.

Ced.

-- 

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


Re: [Tutor] Testing for commandline args

2005-05-17 Thread Cedric BRINER
>  Also, I hear that optparse is much better than getopt.
this is a true pleasure to work with optparse. It was included in python2.3 and 
was primarly called python-optik

Ced.
-- 

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


Re: [Tutor] Python Interest Group Query

2005-05-17 Thread Kent Johnson
Lee Cullens wrote:
> Python Interest Group Query
> 
> I'm aware of the Boston PIG, a smaller one in Amherst and have been  
> told that there is possibly a PIG in Manchester, NH.
> 
> Basically I'm trying to find out if there are any, or any interest in  
> (or even any other Python users at all :~)) in a PIG in the northern  
> NE corridor (Vermont, New Hampshire, Maine).
> 
> I'm a recent Mac and Python convert working at some multimedia
> software development, and retired from a software engineering
> career.  I live in western NH and back in the late 80's commuted to
> Boston and NY, so I'm not very keen on such anymore :~)

I am interested, I live in southern NH (Hollis).

Kent

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


Re: [Tutor] Tutor Digest, Vol 15, Issue 40

2005-05-17 Thread J. Gabriel Schenz

>At 02:17 PM 5/12/2005, Bernard Lebel wrote:
>>Just a generic question: why one would use apply()?
>>
>>In Learning Python, on page 357, there is an example of generating an
>>instance using apply():
>>
>>class A:
>>   def __init__( self, number ):
>>  self.number = number
>>
>>a = apply( A, 3 )
>>What is the benefit of doing this over simply creating an instance "the 
>>usual way":
>>a = A( 3 )
>
>No benefit. See 2.2 Non-essential Built-in Functions in the Python Library 
>Reference. 'Use of apply() is not necessary since the ``extended call 
>syntax,'' as used in the last example, is completely equivalent."
>
>Bob Gailer

Now, I am new to Python as well, but it seems like apply might not be
completely superfluous.  I was thinking that if one were using a functional
programming style, and had to apply a function determined at runtime to an
argument, then one could use this apply to do so.  Granted, you could also
have a dictionary of functions and call the function required as determined
at runtime, but this is stylistically different.

If I am off base on this, I would appreciate someone explaining why.  That
way I can learn this elegant language better.

Regards,
Gabe


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


Re: [Tutor] Opinions about this GIS script

2005-05-17 Thread Ron Phillips


Thank you, Andrei, that's just what I was hoping for -- I wondered about some of those issues, but was a little unsure how to approach a solution. 
 
Ron
 
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 15, Issue 40

2005-05-17 Thread Kent Johnson
J. Gabriel Schenz wrote:
> Now, I am new to Python as well, but it seems like apply might not be
> completely superfluous.  I was thinking that if one were using a functional
> programming style, and had to apply a function determined at runtime to an
> argument, then one could use this apply to do so.  Granted, you could also
> have a dictionary of functions and call the function required as determined
> at runtime, but this is stylistically different.
> 
> If I am off base on this, I would appreciate someone explaining why.  That
> way I can learn this elegant language better.

apply() is superfluous. apply(function, args[, keywords]) is exactly equivalent 
to function(*args, 
[**keywords]). So however you are determining the function to use with apply, 
you can call it 
directly with the newer syntax. In each case, the variable 'function' will be 
bound to a function 
object. For example,

  >>> def foo():
  ...   print 'foo'
  ...
  >>> def bar():
  ...   print 'bar'
  ...
  >>> def pick(arg):
  ...   if arg:
  ... return foo
  ...   else:
  ... return bar
  ...
  >>> myFunc = pick(True)
  >>> apply(myFunc, ())
foo
  >>> myFunc()
foo
  >>> myFunc = pick(False)
  >>> myFunc()
bar

Kent

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


Re: [Tutor] Tkinter questions

2005-05-17 Thread Alberto Troiano
Thanks for the reply

I read the link and I think I've got all what I need (at least for now)

Thanks again

Regards

Alberto

>From: [EMAIL PROTECTED]
>To: Tutor Tutor 
>Subject: Re: [Tutor] Tkinter questions
>Date: Tue, 17 May 2005 11:03:45 +1200 (NZST)
>
>Quoting Alberto Troiano <[EMAIL PROTECTED]>:
>
> > How can I change the background color of a label??
> > How can I change the font-size and make it BOLD??
>
>Check out Fredrik Lundh's _Introduction to Tkinter_:
>http://www.pythonware.com/library/tkinter/introduction/
>
>In particular, the section on widget customization/styling:
>http://www.pythonware.com/library/tkinter/introduction/widget-styling.htm
>
>If you are using Pmw, you can also use Pmw.logicalfont() to change the 
>font.
>
>(eg:
>
>tk = Tk()
>fixed = Pmw.logicalfont(name='Fixed', weight='bold')
>Label(tk, background='blue', font=fixed, text='Hello world!').pack()
>
>)
>
>--
>John.
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


Gaucho


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


[Tutor] Python Interest Group in New England

2005-05-17 Thread Lloyd Kvam
(From digest)
> I'm aware of the Boston PIG, a smaller one in Amherst and have been  
> told that there is possibly a PIG in Manchester, NH.


The Dartmouth Lake Sunapee Linux User Group
http://dlslug.org/
also supports a python mail list.
http://dlslug.org/mailing_lists.html

The Python folks are scattered around the state.  I'm in Lebanon, NH.
Seven people in signed up for python.meetup in Lebanon, but we've never
had more than 4 show up for a meeting.  Sign up for the python-talk list
and let us know you joined.

http://www.gnhlug.org/
I think you'll find the local LUGs will welcome Python folks, even those
using Macs and Windows.


-- 
Lloyd Kvam
Venix Corp

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


[Tutor] I know you will hate this but...

2005-05-17 Thread Smith, Jeff
I'm working on a Python development project which spans multiple people.
We are all working on Windows and using the PyWin IDE.  Our code is
revision controlled using Perforce.  Already we had one instance where
the logical structure of a file was destroyed because indentation levels
were changed along the way.  I can't tell if it was done because PyWin
IDE was setup differently or because Perforce munged things on a
merge...that doesn't really matter.  It seems problematic to me to try
to enforce tool standards on people (IDE and editor settings) which may
or may not take.

My solution has been to require (as a coding standard) ending comments
on control blocks longer than one line.  At least this is something that
could be caught at submit time with an automated review tool.

I'd be interested in how anyone else has solved this problem...provided
you've seen it.

Thanks,
Jeff

P.S. An example of my solution would be:
if some condition:
do stuff
and more stuff
elif another condition:
this is the elif clause
with stuff to do
else:
and the else clause
#endif some condition
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Troubles with Python modules

2005-05-17 Thread Alberto Troiano
Hey

I'm working on Python 2.2 over Linux REd Hat 9.0 and here is the code I have

import os
import sys
import MySQLdb
import datetime
import time

class conexion(object):
def __init__(self):
self.db = MySQLdb.connect(host="localhost", user="administrador", 
passwd="123456",db="seguridad")

def consulta(self,query,args=None):
try:
self.cursor=self.db.cursor()
self.sql=self.cursor.execute(query,args)
except:
self.cerrar()
else:
self.cerrar()

def cerrar(self):
self.db.close()

def getpath():
global ruta
global user
global cam
try:
i=0
for arg in sys.argv:
if i==1:
ruta+=arg
elif i==2:
user=arg
elif i==3:
cam=arg
else:
pass
i+=1
except:
f=open("cotascamonerrors.log","a+")
f.write("ERROR -- No se pudo encontrar el path "+ruta+". 
Contacte al administrador.")
f.close()

def getHoursMinutes(ts=None):
if ts:
t = time.strptime(ts, '%H:%M')
else:
t = time.localtime()
return (t.tm_hour, t.tm_min)


global ruta
global user
global cam
ruta="/var/www/html/home/"
getpath()
os.chdir(ruta)
os.system("mkdir grabacion")
days={1:"Lunes",2:"Martes",3:"Miercoles",4:"Jueves",5:"Viernes",6:"Sabado",7:"Domingo"}
while 1:
hoy=datetime.datetime.now()
dia=days[hoy.isoweekday()]
query="SELECT %s, Limite from camara where CodigoCamara=%s"
args=(dia,cam)
cur=conexion()
cur.consulta(query,args)
res=cur.cursor.fetchall()
for i in res:
horag=i[0]
limite=i[1]
horai1=horag[0:5]
horaf1=horag[6:11]
horai2=horag[12:17]
horaf2=horag[18:23]
if getHoursMinutes(horai1) <= getHoursMinutes() <= 
getHoursMinutes(horaf1):
cur=conexion()
query="SELECT count(*) from imagen where CodigoCamara=%s and 
Usuario=%s"
args(cam,user)
cur.consulta(query,args)
j=cur.cursor.fetchall()
for k in j:
actual=k[0]
if actual < limite:
cur=conexion()
grupo=datetime.datetime.today().strftime("%Y%m%d%H%M%S")
try:
os.system("cp webcam.jpg grabacion/cam"+grupo+".jpg")
query="INSERT INTO imagen values (%s,%s,%s,NOW(),NOW(),%s) 
where CodigoCamara=%s and Usuario=%s"
grupo1=datetime.datetime.today().strftime("%Y%m%d%H%M")
ruta1=ruta+"/grabacion/cam"+grupo+".jpg"
args(user,cam,ruta1,grupo1)
cur.consulta(query,args)
except:
pass
else:
f=open("cotascamonerrors.log","a+")
f.write("ERROR -- El usuario "+user+" agoto su espacio de 
almacenamiento.")
f.close()
elif getHoursMinutes(horai2) <= getHoursMinutes() <= 
getHoursMinutes(horaf2):
cur=conexion()
query="SELECT count(*) from imagen where CodigoCamara=%s and 
Usuario=%s"
args(cam,user)
cur.consulta(query,args)
j=cur.cursor.fetchall()
for k in j:
actual=k[0]
if actual < limite:
cur=conexion()
grupo=datetime.datetime.today().strftime("%Y%m%d%H%M%S")
try:
os.system("cp webcam.jpg grabacion/cam"+grupo+".jpg")
query="INSERT INTO imagen values 
(%s,%s,%s,NOW(),NOW(),%s)where CodigoCamara=%s and Usuario=%s"
grupo1=datetime.datetime.today().strftime("%Y%m%d%H%M")
ruta1=ruta+"/grabacion/cam"+grupo+".jpg"
args(user,cam,ruta1,grupo1)
cur.consulta(query,args)
except:
pass
else:
f=open("cotascamonerrors.log","a+")
f.write("ERROR -- El usuario "+user+" agoto su espacio de 
almacenamiento.")
f.close()
else:
pass


First I'd like to know if this code can be shorter or more efficient (if you 
have the time)

Second the error is the following:

Traceback (most recent call last):
  File "/root/cotascamon.py", line 4, in ?
import datetime
ImportError: No module named datetime

I think this module is in Python 2.3. What can I do??

Then I have installed Python 2.3.4 in the same Linux but I can't use it 
because it doesn't recognze the module MySQLdb

Here is the error

Traceback (most recent call last):
  File "/root/cotascamon.py", line 3, in ?
import MySQLdb
  File "/usr/local/lib/python2.3/site-packages/MySQLdb/__init__.py", line 
27, in ?
import _mysql
ImportError: No module named _mysql

I have cross modules

Modules Python 2.2 - Python 2.3.4

MySQLdb   YES NO

datetimeNO YES

Heelp

Thanks in advanced

Alberto


___

Re: [Tutor] Removing lines in string-table

2005-05-17 Thread Max Noel

On May 17, 2005, at 08:52, Olli Rajala wrote:

> Okay,
> I have a string table (don't recall the right word used in Python
> right now)

 It's called a list, or an array.

> and would like to remove every 'cell' that contains a
> string '_thumb.jpg'. There are 1-> digits before the string if that
> matters. I made a for-loop that does what I want to:
>
> for line in fileNames:
> if line[-10:] == '_thumb.jpg':
> fileNames.remove(line)
>
> But I really doubt that it's not the best way to do this. So, any
> comments are really appreciated.

 Looks like a job for a list comprehension:

fileNames = [element for element in fileNames if not element.endswith 
("_thumb.jpg")]


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


Re: [Tutor] Removing lines in string-table

2005-05-17 Thread Olli Rajala
>  Looks like a job for a list comprehension:
> 
> fileNames = [element for element in fileNames if not element.endswith
> ("_thumb.jpg")]

Thanks Max! It seem to work, but now I have to do some reading,
because I have no idea why it works or what it really does. :) But
thanks anyway.

Yours, 
-- 
Olli Rajala <><
Tampere, Finland
http://www.students.tut.fi/~rajala37/

"In theory, Theory and Practice should be
the same. But in practice, they aren't."
- Murphy's Proverbs
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



[Tutor] Use Strict or Use Warnings was ( Lists of files)

2005-05-17 Thread Mike Hansen
> 
> 
> Subject:
> Re: [Tutor] Lists of files
> From:
> William O'Higgins <[EMAIL PROTECTED]>
> Date:
> Mon, 16 May 2005 15:50:37 -0400
> 
> 
[...]
> 
> One last thing - is there an equivalent of the "use strict" and "use
> warnings" pragmas in Python?  Thanks.

The closest thing I've found is PyChecker. It's kind of like
perl -c hardtoreadperlscript.pl

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


Re: [Tutor] Removing lines in string-table

2005-05-17 Thread Chris Smith

On Tuesday, May 17, 2005, at 08:35 America/Chicago, 
[EMAIL PROTECTED] wrote:

> I have a string table (don't recall the right word used in Python
> right now) and would like to remove every 'cell' that contains a
> string '_thumb.jpg'. There are 1-> digits before the string if that
> matters. I made a for-loop that does what I want to:
>
> for line in fileNames:
> if line[-10:] == '_thumb.jpg':
> fileNames.remove(line)
>
> But I really doubt that it's not the best way to do this. So, any
> comments are really appreciated.
>

The above will not work if two successive lines contain the target 
text. When you remove the one, its neighbor "slides over" to take the 
place of the one removed and then when you proceed to the "next" line 
you are actually skipping the one that slid over.  This could be 
remedied with using indices to access the list, but perhaps a better 
approach is to use filter or a list comprehension to remove the target 
lines:

###
def myfilter(x):
return not x.endswith('_thumb.jpg')
fileNames =filter(myfilter, fileNames)

# OR

fileNames =[x for x in fileNames if not x.endswith('_thumb.jpg')]
###

/c

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


Re: [Tutor] Removing lines in string-table

2005-05-17 Thread Olli Rajala
My code:
> > for line in fileNames:
> > if line[-10:] == '_thumb.jpg':
> > fileNames.remove(line)

Chris wrote:
> The above will not work if two successive lines contain the target
> text. When you remove the one, its neighbor "slides over" to take the
> place of the one removed and then when you proceed to the "next" line
> you are actually skipping the one that slid over.  

Oh, yeah, that's right. I just didn't notice it... Thanks for
correcting me! Actually it wouldn't have mattered (I think) because
the list contains x.jpg and x_thumb.jpg which have been collected by
os.listdir(). At least I suppose that it would be like [x.jpg,
x_thumb.jpg, y.jpg, y_thumb.jpg] or am I completely wrong? But thanks
for good suggestions, I replaced my code with the list comprehension
method and it works now. Thanks!

Yours, 
-- 
Olli Rajala <><
Tampere, Finland
http://www.students.tut.fi/~rajala37/

"In theory, Theory and Practice should be
the same. But in practice, they aren't."
- Murphy's Proverbs
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects in List (fwd)

2005-05-17 Thread Danny Yoo

> Hi Danny
>
> Thanks, it works - I must read the documentation more carefully!
>
> Would you mind if I knok on your door again with futher Python hick-ups?

Hi Danie,

It's probably a better idea to send your questions to Tutor.  The reason
is to allow the community to get involved.

Also, I have the slight tendency to screw up and give mistaken advice
sometimes, and I depend greatly on someone calling me on it and correcting
my mistakes.  *grin* So just from the sake of accountability and
visibility, it's probably best to send questions to the group.


Best of wishes!

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


Re: [Tutor] Lists of files

2005-05-17 Thread Karl Pflästerer
On 16 Mai 2005, [EMAIL PROTECTED] wrote:

> Thanks to all who helped me with my questions regarding testing for
> commandline arguments and list assignment.  I have finished my first
> Python program (included below).  It is slightly more secure than the
> Perl program I rewrote, but also about a tenth of a second slower (0.6
> seconds for Perl on average (100 trials) and 0.7 seconds for Python).

0.1 secs isn't much.  It's not easy to see if such small differences are
according to the program or some side-effects from the OS.  Also the
time till the interpreter/compiler starts will be significant if the
total time is so short.

> Is that typical of Python programs?  I like Python so far, and I'm not
> going to go crazy optimizing working code, but I am curious.

It depends.

> Any pointers, suggestions, etc. are welcome.

I'll write some annotations how you *could* perhaps speed things a
_little_ bit up.

> One last thing - is there an equivalent of the "use strict" and "use
> warnings" pragmas in Python?  Thanks.

No.  There is no need for them IMO since Python doesn't allow such
unsafe constructs as Perl a priori.

> def changebackdrop():
[...]
> command = "/usr/bin/Esetroot"
> # If I was logging into X remotely, this would change.
> commandargs = " -display :0.0 "

I would write these tow as formal parameters (with default values) since
they can change.

> # This is where my backdrops live
> picdir = "/home/willyyam/misc/bmps/"
> 
> if sys.argv[1:]:
> doit = command + commandargs + sys.argv[1]
> os.popen(doit, 'r')

Why you create the variable doit?  Just write directly:
os.popen(command + commandargs + sys.argv[1]

> else:
> files = os.listdir(picdir)

No need for that variable.

> os.chdir(picdir)
> pics = []

No need for that variable.

> for file in files:
> # This is a test for valid images - it includes rgb files,
> # which are not supported by my image software, but the
> # error thrown is not terrible - the image software knows=20
> # what it can and cannot run.
> if imghdr.what(file):
> pics.append(file)
>

No need for that loop.

> randpic = random.choice(pics)

  randpic = random.choice(filter(imghdr.what, os.listdir(picdir)))

That's IMO easier to read and should be a bit faster.

One problem I forgot to mention with that solution is: if there are not
only files but also directories in that picdir you first have to filter
the files since imghdr.what throws an exception if it gets a directory
as argument.

> doit = command + commandargs + picdir + randpic
> os.popen(doit, 'r')

The same as above.

Or you create the variable `doit' but you write the `os.popen' only once
(since after the if statement it will hold the right value for the
command to execute.



   Karl
-- 
Please do *not* send copies of replies to me.
I read the list
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Troubles with Python modules

2005-05-17 Thread Danny Yoo


On Tue, 17 May 2005, Alberto Troiano wrote:

> I'm working on Python 2.2 over Linux REd Hat 9.0 and here is the code I
> have

[code cut]

> First I'd like to know if this code can be shorter or more efficient (if
> you have the time)

Yes.  But let's look at the errors first.



> Second the error is the following:
>
> Traceback (most recent call last):
>   File "/root/cotascamon.py", line 4, in ?
> import datetime
> ImportError: No module named datetime
>
> I think this module is in Python 2.3. What can I do??

I'll assume for the moment that you are using your root account.  Are you
sure that your root account is using Python 2.3?  It may be possible that
the root account has a slightly more restricive PATH than normal user
accounts, and that you might be picking up '/usr/bin/python'.



> Then I have installed Python 2.3.4 in the same Linux but I can't use it
> because it doesn't recognze the module MySQLdb
>
> Here is the error
>
> Traceback (most recent call last):
>   File "/root/cotascamon.py", line 3, in ?
> import MySQLdb
>   File "/usr/local/lib/python2.3/site-packages/MySQLdb/__init__.py", line
> 27, in ?
> import _mysql
> ImportError: No module named _mysql


Different releases of Python will not automatically migrate the old
third-party modules.  You'll need to reinstall MySQLdb for Python 2.3.
MySQLdb can be found here:

http://sourceforge.net/projects/mysql-python




Let's look at some of the code.


> def consulta(self,query,args=None):
> try:
> self.cursor=self.db.cursor()
> self.sql=self.cursor.execute(query,args)
> except:
> self.cerrar()
> else:
> self.cerrar()

The consulta() function tries to make sure that the cerrar()  method is
called, no matter what.  In this case, try/finally may do what you want:

##
try:
...
finally:
self.cerrar()
##



> def getpath():
> global ruta
> global user
> global cam
> try:
> i=0
> for arg in sys.argv:
> if i==1:
> ruta+=arg
> elif i==2:
> user=arg
> elif i==3:
> cam=arg
> else:
> pass
> i+=1
> except:
> f=open("cotascamonerrors.log","a+")
> f.write("ERROR -- No se pudo encontrar el path "+ruta+".
> Contacte al administrador.")
> f.close()

This looks like it's trying to do argument parsing, storing state in
global variables.  You may want to see if you can avoid the globals, and
instead just return those three values back to the caller.

My nervousness with the globals comes from the requirement that getpath()
has to assume that 'ruta' already has some sort of value already.  So
there's already a dependency that can be more clearly documented by making
getpath() take in an initial base path argument:

##
def getpath(base_path):
...
return (ruta, user, cam)
##


But the block above also feels a little awkward because it assumes that
any exception that occurs has to be a path problem.  That might not
necessarily be the case.  I'd strongly recommend letting the exception
speak for itself.  traceback.print_exc() can help:

http://www.python.org/doc/lib/module-traceback.html

##
try:

except:
f = open("cotascamonerrors.log", "a+")
traceback.print_exc(file=f)
f.close()
##


Up to this point, though, things are pretty ok, with the nice helper
functions with clear roles.  The large block near the bottom, though,
needs work.  I'd recommend applying the same helper-function breakup to
make the code's intent clearer.


For example, here's SQL code that's repeated, a.  It should be broken out:

> try:
> os.system("cp webcam.jpg grabacion/cam"+grupo+".jpg")
> query="INSERT INTO imagen values (%s,%s,%s,NOW(),NOW(),%s)
> where CodigoCamara=%s and Usuario=%s"
> grupo1=datetime.datetime.today().strftime("%Y%m%d%H%M")
> ruta1=ruta+"/grabacion/cam"+grupo+".jpg"
> args(user,cam,ruta1,grupo1)
> cur.consulta(query,args)
> except:
> pass


Again, try not to obscure exceptions.  If something bad happens, you
really want the exception to tell you what happened: it is not fun to
debug something when the error message is insufficiently helpful.  Change
the except block to log the error message.



I do not understand what's happening with args() above:

> args(user,cam,ruta1,grupo1)

Do you mean:

  args = (user,cam,ruta1,grupo1)

instead?


Hope this helps!

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


Re: [Tutor] I know you will hate this but...

2005-05-17 Thread Andrei
Smith, Jeff  medplus.com> writes:   
> merge...that doesn't really matter.  It seems problematic to me to try   
> to enforce tool standards on people (IDE and editor settings) which may   
> or may not take.   
   
It seems problematic to me to NOT enforce standard *settings* (e.g. 4 spaces   
per indentation level, no tabs). Any IDE can be used as long as the proper   
settings are configured. Inconsistent indentation styles are very annoying in   
other languages, but a fatal problem in Python.   
   
> My solution has been to require (as a coding standard) ending comments   
> on control blocks longer than one line.  At least this is something that   
> could be caught at submit time with an automated review tool.   
   
Weird. Looks to me like the wrong solution (it would IMO be better to find out 
who committed the broken code and work from there to find the cause), but 
whatever works for you.   
   
> I'd be interested in how anyone else has solved this problem...provided   
> you've seen it.   
   
I haven't, but I use Subversion and haven't done team development in Python. 
But I don't think any half-decent VCS should go around modifying code on its 
own in *any* way, even if it's spaces. Although, now that I think about it, a 
VCS might have an option of ignoring leading/trailing whitespace when doing 
diffs, such an option could bite when merging Python code. 
 
Yours, 
 
Andrei 

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


[Tutor] using -i flag with '''if __name__ == "__main__":'''

2005-05-17 Thread Terry Carroll

I've often found it convenient to run a Python program I'm developing with 
the -i flag. I find it convenient to use as a post-mortem as it hits bugs, 
or to explore data structures.

I've recently started using the construct 

  if __name__ == "__main__":
 main()

And found I can't do the -i thing effectively any more.  What's a good 
equivalent approach?

To use a trivial example, if I have the following program (t2.py):

i = 0
k = 4/i
print i, k

I can do this:

C:\>python -i t2.py
Traceback (most recent call last):
  File "t2.py", line 2, in ?
k = 4/i
ZeroDivisionError: integer division or modulo by zero
>>> i
0
>>>

But if the program is like this:

def main():
   i = 0
   k = 4/i
   print i, k

if __name__ == "__main__":
   main()

That won't work:

C:\>python -i t1.py
Traceback (most recent call last):
  File "t1.py", line 7, in ?
main()
  File "t1.py", line 3, in main
k = 4/i
ZeroDivisionError: integer division or modulo by zero
>>> i
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'i' is not defined
>>>


I understand *why* it won't work; I'm just looking for a nice 
easy way to do the same sort of thing I used to do before I 
started using '''if __name__ == "__main__":'''

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


Re: [Tutor] I know you will hate this but...

2005-05-17 Thread Smith, Jeff
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Andrei
>It seems problematic to me to NOT enforce standard *settings* (e.g. 4
spaces   
>per indentation level, no tabs). Any IDE can be used as long as the
proper   
>settings are configured. Inconsistent indentation styles are very
annoying in   
>other languages, but a fatal problem in Python.   

But there is no way to enforce standard settings.  When new versions are
installed or someone just makes a mistake the settings might change and
you won't know until it's too late...possibly weeks later.

   
>Weird. Looks to me like the wrong solution (it would IMO be better to
find out 
>who committed the broken code and work from there to find the cause),
but 
>whatever works for you.   

I agree I don't like it much either, but finding out who broke the code
doesn't prevent the problem from happening again.  My plan is to
eventually produce a tool that will verify that this coding standard is
met which allows us to recover the logical structure should this happen
on an ongoing basis.  

   
>I haven't, but I use Subversion and haven't done team development in
Python. 
>But I don't think any half-decent VCS should go around modifying code
on its 
>own in *any* way, even if it's spaces. Although, now that I think about
it, a 
>VCS might have an option of ignoring leading/trailing whitespace when
doing 
>diffs, such an option could bite when merging Python code. 
 
Every CMS I've used modified code in some way.  CVS, RCS, VSS, Perforce,
and Subversion support the use of keywords.  All of these tools, as well
as Clearcase have merge tools to merge changes between branches in an
automated way.  At the core level, all these tools work by tearing apart
the source and saving the diffs between revisions and then putting them
back together again when a specific revision is requested.  Sure you
hope it's the same as it was in the beginning but there's always a
chance for error.

I don't know where the error was introduced in my case, It's either the
PyWin settings or the Perforce merge tool.  I have control over one but
not the other.  In either case, we need a system that can allow us to
recover from this situation when it happens.

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


Re: [Tutor] I know you will hate this but...

2005-05-17 Thread Kent Johnson
Smith, Jeff wrote:
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Andrei
>>Weird. Looks to me like the wrong solution (it would IMO be better to find 
>>out 
>>who committed the broken code and work from there to find the cause), but 
>>whatever works for you.   
> 
> 
> I agree I don't like it much either, but finding out who broke the code
> doesn't prevent the problem from happening again.  My plan is to
> eventually produce a tool that will verify that this coding standard is
> met which allows us to recover the logical structure should this happen
> on an ongoing basis.  

Take a look at the tabnanny module, it might help.

Kent

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


Re: [Tutor] Troubles with Python modules

2005-05-17 Thread Alberto Troiano
First of all, thanks for the corrections
I'm assuming that Python 2.2 doesn't have datetime module then???
Is there any way to install it???
My version of Python 2.3.4 is an alternative installation so I know that 
when I type python with my root account its going to Python 2.2.2 (I'm using 
the root account) I changed the link though so when I say Python I enter 
Python 2.3.4 (works and checked)

I'm sending the errors MySQLdb gives me when I try to install it. It's 
hola.txt file
I'm doing python setup.py build and inside hola.txt you can see what it says
I have installed Linux Red Hat with ALL packages

Can I add datetime module to Python 2.2.2 ??
If so how???
Regards
Alberto
From: Danny Yoo <[EMAIL PROTECTED]>
To: Alberto Troiano <[EMAIL PROTECTED]>
CC: Tutor 
Subject: Re: [Tutor] Troubles with Python modules
Date: Tue, 17 May 2005 09:58:10 -0700 (PDT)

On Tue, 17 May 2005, Alberto Troiano wrote:
> I'm working on Python 2.2 over Linux REd Hat 9.0 and here is the code I
> have
[code cut]
> First I'd like to know if this code can be shorter or more efficient (if
> you have the time)
Yes.  But let's look at the errors first.

> Second the error is the following:
>
> Traceback (most recent call last):
>   File "/root/cotascamon.py", line 4, in ?
> import datetime
> ImportError: No module named datetime
>
> I think this module is in Python 2.3. What can I do??
I'll assume for the moment that you are using your root account.  Are you
sure that your root account is using Python 2.3?  It may be possible that
the root account has a slightly more restricive PATH than normal user
accounts, and that you might be picking up '/usr/bin/python'.

> Then I have installed Python 2.3.4 in the same Linux but I can't use it
> because it doesn't recognze the module MySQLdb
>
> Here is the error
>
> Traceback (most recent call last):
>   File "/root/cotascamon.py", line 3, in ?
> import MySQLdb
>   File "/usr/local/lib/python2.3/site-packages/MySQLdb/__init__.py", 
line
> 27, in ?
> import _mysql
> ImportError: No module named _mysql

Different releases of Python will not automatically migrate the old
third-party modules.  You'll need to reinstall MySQLdb for Python 2.3.
MySQLdb can be found here:
http://sourceforge.net/projects/mysql-python

Let's look at some of the code.
> def consulta(self,query,args=None):
> try:
> self.cursor=self.db.cursor()
> self.sql=self.cursor.execute(query,args)
> except:
> self.cerrar()
> else:
> self.cerrar()
The consulta() function tries to make sure that the cerrar()  method is
called, no matter what.  In this case, try/finally may do what you want:
##
try:
...
finally:
self.cerrar()
##

> def getpath():
> global ruta
> global user
> global cam
> try:
> i=0
> for arg in sys.argv:
> if i==1:
> ruta+=arg
> elif i==2:
> user=arg
> elif i==3:
> cam=arg
> else:
> pass
> i+=1
> except:
> f=open("cotascamonerrors.log","a+")
> f.write("ERROR -- No se pudo encontrar el path "+ruta+".
> Contacte al administrador.")
> f.close()
This looks like it's trying to do argument parsing, storing state in
global variables.  You may want to see if you can avoid the globals, and
instead just return those three values back to the caller.
My nervousness with the globals comes from the requirement that getpath()
has to assume that 'ruta' already has some sort of value already.  So
there's already a dependency that can be more clearly documented by making
getpath() take in an initial base path argument:
##
def getpath(base_path):
...
return (ruta, user, cam)
##
But the block above also feels a little awkward because it assumes that
any exception that occurs has to be a path problem.  That might not
necessarily be the case.  I'd strongly recommend letting the exception
speak for itself.  traceback.print_exc() can help:
http://www.python.org/doc/lib/module-traceback.html
##
try:

except:
f = open("cotascamonerrors.log", "a+")
traceback.print_exc(file=f)
f.close()
##
Up to this point, though, things are pretty ok, with the nice helper
functions with clear roles.  The large block near the bottom, though,
needs work.  I'd recommend applying the same helper-function breakup to
make the code's intent clearer.
For example, here's SQL code that's repeated, a.  It should be broken out:
> try:
> os.system("cp webcam.jpg grabacion/cam"+grupo+".jpg")
> query="INSERT INTO imagen values 
(%s,%s,%s,NOW(),NOW(),%s)
> where CodigoCamara=%s and Usuario=%s"
> grupo1=datetime.datetime.today().strftime("%Y%m%d%H%M")
> ruta1=ruta+"/grabacion/cam"+grupo+".jpg"
> args(user,cam,ruta1,grupo1)
>

Re: [Tutor] Problem with a while loop.

2005-05-17 Thread Goldie, Josh
import random

head = 0
tail = 0

while (head + tail) < 100:
coin = random.randrange(2)  <-- move this line inside the loop
if coin == 0: 



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of . ,
Sent: Tuesday, May 17, 2005 4:12 PM
To: tutor@python.org
Subject: [Tutor] Problem with a while loop.

Hi,

I'm writing a program that is a program that flips a coin 100 times and
then tells the number of heads and tails.


---

import random

head = 0
tail = 0
coin = random.randrange(2)

while (head + tail) < 100:
if coin == 0:
print "head"
head += 1

elif coin == 1:
print "tail"
tail += 1

else:
print "Error"


raw_input("")


---

The problem is the program prints like..
tail
tail
tail
.
.
.

Help me!

_
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.com/

___
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] Troubles with Python modules

2005-05-17 Thread Alberto Troiano
Hey Danny

Sorry about the question marks (MSN addiction :))

Didn't work and as I suspected it was already installed.
What else can I do? Is there another built-in module that resemble datetime 
module?

I had to use Python 2.2.2 because of MySQLdb but now I can't use datetime. 
As you see I'm in the middle of the wall and the sword

thanks for any help you can give me

Best Regards

Alberto

>From: Danny Yoo <[EMAIL PROTECTED]>
>To: Alberto Troiano <[EMAIL PROTECTED]>
>CC: Tutor 
>Subject: Re: [Tutor] Troubles with Python modules
>Date: Tue, 17 May 2005 13:26:09 -0700 (PDT)
>
>
>On Tue, 17 May 2005, Alberto Troiano wrote:
>
>
> > I'm sending the errors MySQLdb gives me when I try to install it. It's
> > hola.txt file
> > I'm doing python setup.py build and inside hola.txt you can see what it 
>says
> > I have installed Linux Red Hat with ALL packages
>
>Hi Alberto,
>
>
>[Side note: please avoid using the plaintive '??' in your questions.
>it just reads in a way that feels like begging; you don't need to do
>that.]
>
>Red Hat's "Install All Packages" might not actually install all the
>packages you need --- I suspect that it might not include developer
>packages.  According to the error messages:
>
>##
>gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
>-Wstrict-prototypes
>-fPIC -I/usr/local/include/python2.3 -c _mysql.c -o
>build/temp.linux-i686-2.3/_mysql.o -I'/usr/include/mysql'
>_mysql.c:41:19: mysql.h: No such file or directory
>##
>
>the necessary MySQL header files can't be found in '/usr/include/mysql'.
>You mentioned Red Hat 9, so you probably need to install something like
>the 'mysql-devel-3.23.54a-11.i386.rpm' file.  Here is a link to a mirror
>with that file:
>
>ftp://ftp.linux.ncsu.edu/pub/redhat/linux/9/en/os/i386/RedHat/RPMS/mysql-devel-3.23.54a-11.i386.rpm
>
>
>
> > Can I add datetime module to Python 2.2.2?
>
>You may find:
>
> http://www.egenix.com/files/python/mxDateTime.html
>
>useful, although I can't confirm that it has the exact same API as the one
>in the Standard Library.
>


Gaucho


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


[Tutor] Problem with a while loop.

2005-05-17 Thread . ,
Hi,

I'm writing a program that is a program that flips a coin 100 times and
then tells the number of heads and tails.

---

import random

head = 0
tail = 0
coin = random.randrange(2)

while (head + tail) < 100:
if coin == 0:
print "head"
head += 1

elif coin == 1:
print "tail"
tail += 1

else:
print "Error"


raw_input("")

---

The problem is the program prints like..
tail
tail
tail
.
.
.

Help me!

_
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.com/

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


Re: [Tutor] YATENJoe

2005-05-17 Thread Joseph Quigley


If you intend to make a text
editor (something which allows the user to browse
through the text and manipulate it at will) using just raw_input and
print, I
think you've set yourself an impossible task. For a console editor you
should
probably look at curses
(http://www.amk.ca/python/howto/curses/)
- which don't
work on Windows, so you'll probably need this:
http://adamv.com/dev/python/curses/
(but according to the site it's incomplete).
Ok.
lines = []
while True:
    lines.append(raw_input(''))
(But that offers no way to e.g. save and continue.)
Ok again.
Text editors are IMO not applications suitable for learning vanilla Python, or
OOP for that matter. Text editors are used as example applications in the RAD
IDE world (VB, Delphi and such) because in those environments a text editor is
literally three clicks away (click on memo component, click on form, click on
run). Vanilla Python has no GUI, so no memo component - hence my recommendation
for Tkinter or wxPython. PythonCard and Boa provide an experience somewhat
similar to commercial RAD IDE's if that's what you're looking for.
I got my idea from looking at Nano, Vi, Joe and a few other UNIX text editors. Nano and Joe are console programs. That's why I thought I would try a console ed. in Python.

Having one function for each line is a bad idea whether you code it by hand or
automatically
Ah.
A function implements certain behavior. Having the same behavior (raw_input)
implemented separately for each line is an extremely wasteful way of
programming.
Is there a way of telling Python to make a new line after you press Enter (return)?
I would suggest that you learn a bit more about Python's facilities before
embarking on an ambitious project :) - you won't get very far without knowing
how to use lists and dictionaries.
So that's one of the ways Dicts, and lists are used for? I never could fully grasp their use.
Thanks,
JQ

---
Proud to be a true hacker
(You may have a bad impression of the word "hacker". Do some homework,
go to: http://catb.org/~esr/faqs/hacker-howto.html and become enlightened) 

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


[Tutor] Perl equivalent of $#var

2005-05-17 Thread Smith, Jeff
Is there a more Pythonic way to get the Perl equivalent of
$#var
other than
len(var) - 1

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


Re: [Tutor] Troubles with Python modules

2005-05-17 Thread Danny Yoo

On Tue, 17 May 2005, Alberto Troiano wrote:


> I'm sending the errors MySQLdb gives me when I try to install it. It's
> hola.txt file
> I'm doing python setup.py build and inside hola.txt you can see what it says
> I have installed Linux Red Hat with ALL packages

Hi Alberto,


[Side note: please avoid using the plaintive '??' in your questions.
it just reads in a way that feels like begging; you don't need to do
that.]

Red Hat's "Install All Packages" might not actually install all the
packages you need --- I suspect that it might not include developer
packages.  According to the error messages:

##
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes
-fPIC -I/usr/local/include/python2.3 -c _mysql.c -o
build/temp.linux-i686-2.3/_mysql.o -I'/usr/include/mysql'
_mysql.c:41:19: mysql.h: No such file or directory
##

the necessary MySQL header files can't be found in '/usr/include/mysql'.
You mentioned Red Hat 9, so you probably need to install something like
the 'mysql-devel-3.23.54a-11.i386.rpm' file.  Here is a link to a mirror
with that file:

ftp://ftp.linux.ncsu.edu/pub/redhat/linux/9/en/os/i386/RedHat/RPMS/mysql-devel-3.23.54a-11.i386.rpm



> Can I add datetime module to Python 2.2.2?

You may find:

http://www.egenix.com/files/python/mxDateTime.html

useful, although I can't confirm that it has the exact same API as the one
in the Standard Library.

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


Re: [Tutor] Perl equivalent of $#var

2005-05-17 Thread Max Noel

On May 17, 2005, at 22:00, Smith, Jeff wrote:

> Is there a more Pythonic way to get the Perl equivalent of
> $#var
> other than
> len(var) - 1

 AFAIK, len(var) - 1 is the only way. Note, however, that the  
last element of a list (or of any ordered sequence) can be obtained  
with the shortcut var[-1].

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"

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


[Tutor] Menu help

2005-05-17 Thread Alberto Troiano
Hey
I know I posted so many things but it's because I have so much to do
I used to program in VB 6 but I want to learn a programming so I can I 
master it.

I want to make a menu (Tkinter) like the one of the image attached to this 
email
I can do the menu and submenu but I can't do the third submenu

Help me!
Regards
Alberto
<>___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Troubles with Python modules

2005-05-17 Thread Danny Yoo


On Tue, 17 May 2005, Alberto Troiano wrote:

> Sorry about the question marks (MSN addiction :))
>
> Didn't work and as I suspected it was already installed.

Hi Alberto,

I'm still thinking that the MySQL development packages are either damaged
or mixed up, since the error message says that it can't find MySQL's
headers.

Let's double check something.  Can you do the following from your Unix
shell?

##
$ rpm -qil mysql-devel
$ ls -l /usr/include/mysql
##

Show us what comes out.

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


Re: [Tutor] Perl equivalent of $#var

2005-05-17 Thread Danny Yoo


On Tue, 17 May 2005, Smith, Jeff wrote:

> Is there a more Pythonic way to get the Perl equivalent of
>   $#var
> other than
>   len(var) - 1


Hi Jeff,

Just out of curiosity, where do you use Perl's $#var?  Can you show us the
context of its use?  If we see context, it might help us find a Python
idiom that fits the usage.

Best of wishes!

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


Re: [Tutor] Troubles with Python modules

2005-05-17 Thread Alberto Troiano
Here you go
Each filenaem corresponds to the command
Thanks in advanced
Alberto
From: Danny Yoo <[EMAIL PROTECTED]>
To: Alberto Troiano <[EMAIL PROTECTED]>
CC: tutor@python.org
Subject: Re: [Tutor] Troubles with Python modules
Date: Tue, 17 May 2005 14:56:52 -0700 (PDT)

On Tue, 17 May 2005, Alberto Troiano wrote:
> Sorry about the question marks (MSN addiction :))
>
> Didn't work and as I suspected it was already installed.
Hi Alberto,
I'm still thinking that the MySQL development packages are either damaged
or mixed up, since the error message says that it can't find MySQL's
headers.
Let's double check something.  Can you do the following from your Unix
shell?
##
$ rpm -qil mysql-devel
$ ls -l /usr/include/mysql
##
Show us what comes out.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Gaucho
Name: mysql-devel Relocations: (not 
relocateable)
Version : 3.23.54a Vendor: Red Hat, Inc.
Release : 11   Build Date: Tue 18 Feb 
2003 03:48:26 PM BOT
Install Date: Wed 20 Apr 2005 03:07:32 PM BOT  Build Host: 
porky.devel.redhat.com
Group   : Applications/Databases   Source RPM: 
mysql-3.23.54a-11.src.rpm
Size: 1520790 License: LGPL
Signature   : DSA/SHA1, Mon 24 Feb 2003 02:38:50 AM BOT, Key ID 
219180cddb42a60e
Packager: Red Hat, Inc. 
URL : http://www.mysql.com
Summary : Files for development of MySQL applications.
Description :
MySQL is a true multi-user, multi-threaded SQL database server. This
package contains the libraries and header files that are needed for
developing MySQL applications.
/usr/include/mysql
/usr/include/mysql/dbug.h
/usr/include/mysql/errmsg.h
/usr/include/mysql/m_ctype.h
/usr/include/mysql/m_string.h
/usr/include/mysql/my_config.h
/usr/include/mysql/my_global.h
/usr/include/mysql/my_list.h
/usr/include/mysql/my_net.h
/usr/include/mysql/my_no_pthread.h
/usr/include/mysql/my_pthread.h
/usr/include/mysql/my_sys.h
/usr/include/mysql/mysql.h
/usr/include/mysql/mysql_com.h
/usr/include/mysql/mysql_version.h
/usr/include/mysql/mysqld_error.h
/usr/include/mysql/raid.h
/usr/include/mysql/sslopt-case.h
/usr/include/mysql/sslopt-longopts.h
/usr/include/mysql/sslopt-usage.h
/usr/include/mysql/sslopt-vars.h
/usr/lib/mysql
/usr/lib/mysql/libdbug.a
/usr/lib/mysql/libheap.a
/usr/lib/mysql/libmerge.a
/usr/lib/mysql/libmyisam.a
/usr/lib/mysql/libmyisammrg.a
/usr/lib/mysql/libmysqlclient.a
/usr/lib/mysql/libmysqlclient.so
/usr/lib/mysql/libmysqlclient_r.a
/usr/lib/mysql/libmysqlclient_r.so
/usr/lib/mysql/libmystrings.a
/usr/lib/mysql/libmysys.a
/usr/lib/mysql/libnisam.a
total 204
-rw-r--r--1 root root 3445 Feb 18  2003 dbug.h
-rw-r--r--1 root root 2082 Feb 18  2003 errmsg.h
-rw-r--r--1 root root 5864 Feb 18  2003 m_ctype.h
-rw-r--r--1 root root 7594 Feb 18  2003 m_string.h
-rw-r--r--1 root root22431 Feb 18  2003 my_config.h
-rw-r--r--1 root root32038 Feb 18  2003 my_global.h
-rw-r--r--1 root root 1579 Feb 18  2003 my_list.h
-rw-r--r--1 root root 2696 Feb 18  2003 my_net.h
-rw-r--r--1 root root 1205 Feb 18  2003 my_no_pthread.h
-rw-r--r--1 root root22737 Feb 18  2003 my_pthread.h
-rw-r--r--1 root root 8677 Feb 18  2003 mysql_com.h
-rw-r--r--1 root root 8188 Feb 18  2003 mysqld_error.h
-rw-r--r--1 root root10787 Feb 18  2003 mysql.h
-rw-r--r--1 root root  590 Feb 18  2003 mysql_version.h
-rw-r--r--1 root root25751 Feb 18  2003 my_sys.h
-rw-r--r--1 root root 5869 Feb 18  2003 raid.h
-rw-r--r--1 root root 1605 Feb 18  2003 sslopt-case.h
-rw-r--r--1 root root 1296 Feb 18  2003 sslopt-longopts.h
-rw-r--r--1 root root 1239 Feb 18  2003 sslopt-usage.h
-rw-r--r--1 root root 1013 Feb 18  2003 sslopt-vars.h
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using -i flag with '''if __name__ == "__main__":'''

2005-05-17 Thread jfouhy
Quoting Terry Carroll <[EMAIL PROTECTED]>:

> I've recently started using the construct 
> 
>  if __name__ == "__main__":
>  main()
> 
> And found I can't do the -i thing effectively any more. What's a good 
> equivalent approach?

If main is a class, you could change to 'm = main()'; that would at least give
you access to the class attributes.

Another possibility is to look at this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287

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


Re: [Tutor] Tutor Digest, Vol 15, Issue 40

2005-05-17 Thread jfouhy
Quoting Kent Johnson <[EMAIL PROTECTED]>:

> J. Gabriel Schenz wrote:
> > Now, I am new to Python as well, but it seems like apply might not be
> > completely superfluous. I was thinking that if one were using a functional
> > programming style, and had to apply a function determined at runtime to an
> > argument, then one could use this apply to do so. 
> apply() is superfluous. apply(function, args[, keywords]) is exactly
> equivalent to function(*args, [**keywords]). 

Ooh.  Functional programming is fun!

>>> multers = [i.__mul__ for i in range(10)]
>>> mulTable = [[f(i) for i in range(10)] for f in multers]
>>> import pprint
>>> pprint.pprint(mulTable)
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
 [0, 2, 4, 6, 8, 10, 12, 14, 16, 18],
 [0, 3, 6, 9, 12, 15, 18, 21, 24, 27],
 [0, 4, 8, 12, 16, 20, 24, 28, 32, 36],
 [0, 5, 10, 15, 20, 25, 30, 35, 40, 45],
 [0, 6, 12, 18, 24, 30, 36, 42, 48, 54],
 [0, 7, 14, 21, 28, 35, 42, 49, 56, 63],
 [0, 8, 16, 24, 32, 40, 48, 56, 64, 72],
 [0, 9, 18, 27, 36, 45, 54, 63, 72, 81]]

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


[Tutor] hettingertools?

2005-05-17 Thread D. Hartley
This was a hint from a python challenge, but I can't find anything
about it online: Anyone know?

Thanks :)

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


Re: [Tutor] using -i flag with '''if __name__ == "__main__":'''

2005-05-17 Thread Terry Carroll
On Wed, 18 May 2005 [EMAIL PROTECTED] wrote:

> If main is a class, you could change to 'm = main()'; that would at
> least give you access to the class attributes.

Interesting approach; I'm refering to where main() is a method, the usual 
python idiom.


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


Re: [Tutor] hettingertools?

2005-05-17 Thread Terry Carroll
On Tue, 17 May 2005, D. Hartley wrote:

> This was a hint from a python challenge, but I can't find anything
> about it online: Anyone know?

Raymond Hettinger is a frequent contributor to Python.  I don't know if 
that is part of it.

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


Re: [Tutor] hettingertools?

2005-05-17 Thread Terry Carroll
On Tue, 17 May 2005, Terry Carroll wrote:

> On Tue, 17 May 2005, D. Hartley wrote:
> 
> > This was a hint from a python challenge, but I can't find anything
> > about it online: Anyone know?
> 
> Raymond Hettinger is a frequent contributor to Python.  I don't know if 
> that is part of it.

And actually, I think he was behind itertools, come to think of it.

You're obviously further along the challenges than I am.  I'm on #9 now.  
My defense is that I'm not a programmer by occupation, so I do these in my
Copious Spare Time in the evenings.

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


Re: [Tutor] hettingertools?

2005-05-17 Thread jfouhy
Quoting Terry Carroll <[EMAIL PROTECTED]>:

> On Tue, 17 May 2005, D. Hartley wrote:
> > This was a hint from a python challenge, but I can't find anything
> > about it online: Anyone know?
> Raymond Hettinger is a frequent contributor to Python. I don't know if 
> that is part of it.

If I had to guess, I would guess: itertools.
(http://python.org/doc/2.3.5/whatsnew/node18.html)

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


Re: [Tutor] Tutor Digest, Vol 15, Issue 40

2005-05-17 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> Quoting Kent Johnson <[EMAIL PROTECTED]>:
> 
> 
>>J. Gabriel Schenz wrote:
>>
>>>Now, I am new to Python as well, but it seems like apply might not be
>>>completely superfluous. I was thinking that if one were using a functional
>>>programming style, and had to apply a function determined at runtime to an
>>>argument, then one could use this apply to do so. 
>>
>>apply() is superfluous. apply(function, args[, keywords]) is exactly
>>equivalent to function(*args, [**keywords]). 
> 
> 
> Ooh.  Functional programming is fun!
> 
> 
multers = [i.__mul__ for i in range(10)]
mulTable = [[f(i) for i in range(10)] for f in multers]

or use mulTable = [[i*j for i in range(10)] for j in range(10)] if you prefer 
conciseness and 
readability :-)

Kent

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


Re: [Tutor] using -i flag with '''if __name__ == "__main__":'''

2005-05-17 Thread Kent Johnson
Terry Carroll wrote:
> I've often found it convenient to run a Python program I'm developing with 
> the -i flag. I find it convenient to use as a post-mortem as it hits bugs, 
> or to explore data structures.
> 
> I've recently started using the construct 
> 
>   if __name__ == "__main__":
>  main()

I think this approach to debugging won't scale well and you are just seeing the 
tip of the iceberg. 
As your programs get more complex you will encapsulate more and more 
functionality into functions 
and classes and the variables they use will not in general be visible from the 
global scope.

I often find that the information in the traceback and exception are enough to 
figure out the 
problem; if not, a few print statements can help. You will get better at this 
with experience.
An alternative is to use a debugger such as pdb or the one built into IDLE.

This recipe looks interesting - it dumps the values of the variables at the 
time of an uncaught 
exception. I haven't tried it but it looks like it could be useful when 
combined with the excepthook 
recipe John cited:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215

Kent

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


[Tutor] game instructions

2005-05-17 Thread EUGENE ASTLEY








Following the Tutorial by Michael Dawson and the previous
web help from Liam Clark, I have a basic Othello Game up and running quite
well.

I now want to start the game with a set of instructions that
stays on the screen until the user is ready to proceed. Since you are only
allowed one screen, I am now confused as to how I can accomplish this.

My program starts by defining global constants SCREEN_WIDTH = 1024 and
SCREEN_HEIGHT=768 and THE_SCREEN = games.Screen(SCREEN_WIDTH, SCREEN_HEIGHT) 

Then after writing all the classes, sprites etc I define main() as follows:

 

def main():

my_screen = THE_SCREEN

board_image=games.load_image(“OthelloImage.jpg”)

my_screen.set_background(board_image)

 

# then I create some board pieces etc and end
with

my_screen.mainloop()

 

main()

Thank you for any help.

Gene






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


[Tutor] help me on python + snack

2005-05-17 Thread Mahmad Sadique Hannure
Hello friends,
I m currently working on sound stuff. I have installed
all stuff related to Snack. My code for playing mp3
song is like this

#!/usr/bin/python2.3

from Tkinter import *
import tkSnack

def main():
root = Tk()
tkSnack.initializeSnack(root)
mysound = tkSnack.Sound('xyz.mp3')
#mysound.read()
mysound.play()
if __name__=='__main__':
main()
I works fine without any error but can't get any
sound.

So friend help me, I don't know whats wroung with my
code.

Help!

Thank You.

Regards,
Mahmad Sadique.




__ 
Do you Yahoo!? 
Make Yahoo! your home page 
http://www.yahoo.com/r/hs
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] YATENJoe

2005-05-17 Thread Andrei
Joseph Quigley  gmail.com> writes:

> Is there a way of telling Python to make a new line after you press Enter
(return)?

Return automatically ends the current input line (and therefore starts a new
one) when you use raw_input.

>> I would suggest that you learn a bit more about Python's facilities before
>> embarking on an ambitious project :) - you won't get very far without knowing
>> how to use lists and dictionaries.

> So that's one of the ways Dicts, and lists are used for? I never could fully
grasp their use.

Perhaps you should have a look at "How to think like a computer scientist in
Python" (http://www.ibiblio.org/obp/thinkCSpy/). Chapters 8 and 10 discuss Lists
and Dictionaries
  http://www.ibiblio.org/obp/thinkCSpy/chap08.htm
  http://www.ibiblio.org/obp/thinkCSpy/chap10.htm ,

but I'd recommend you read all of it (or another Python tutorial).

Yours,

Andrei

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