Re: [Tutor] First program

2010-03-13 Thread Alan Gauld
"Ray Parrish"  wrote 

print "A %s with dimensions %sx%s has an area of %s." % (choice, 
height, width, width*height)


Isn't it a little more understandable to use a 
construct like the following?


print "The area of a " + Choice + "is " str(Width) + " x " + 
str(Height) + " equals " + str(Width * Height) + " 
square feet"


It depends on where you come from.
Those of us brought up on C or COBOL are used to separating 
the presentation from the data. Those brought up with PASCAL 
and BASIC are used to iterleaving data with presentation.


One thing - you don't need all the str() calls in your example, 
print already calls str() for you. Also comma separators are 
better than + signs since the plus operation on strings is 
quite expensive - you create a new string for each addition.


HTH,

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

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


Re: [Tutor] First program

2010-03-13 Thread Luke Paireepinart
On Sat, Mar 13, 2010 at 3:03 AM, Alan Gauld wrote:

> "Ray Parrish"  wrote
>
>>print "A %s with dimensions %sx%s has an area of %s." % (choice,
>>> height, width, width*height)
>>>
>>>  Isn't it a little more understandable to use a construct like the
>> following?
>>
>>  print "The area of a " + Choice + "is " str(Width) + " x " +
>
 str(Height) + " equals " + str(Width * Height) + " square feet"
>>
>
> It depends on where you come from.
> Those of us brought up on C or COBOL are used to separating the
> presentation from the data. Those brought up with PASCAL and BASIC are used
> to iterleaving data with presentation.
>
> One thing - you don't need all the str() calls in your example, print
> already calls str() for you. Also comma separators are better than + signs
> since the plus operation on strings is quite expensive - you create a new
> string for each addition.
>
>
> print actually doesn't call str if you use concatenation.  So the str()
calls are necessary if you do not use "," but use "+" instead.
So there are at least 2 reasons why + is worse than comma.
Another thing to be aware of is that if you use commas,
print inserts a space in the string, which may be either an advantage or a
disadvantage depending on what you're trying to do.

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


Re: [Tutor] %s %r with cutom type

2010-03-13 Thread spir
On Sat, 13 Mar 2010 13:50:55 +1100
Steven D'Aprano  wrote:

> On Fri, 12 Mar 2010 10:29:17 pm spir wrote:
> > Hello again,
> >
> > A different issue. On the custom Unicode type discussed in another
> > thread, I have overloaded __str__ and __repr__ to get encoded byte
> > strings (here with debug prints & special formats to distinguish from
> > builtin forms):
> [...]
> > Note that Unicode.__str__ is called neither by "print us", nore by
> > %s. What happens? Why does the issue only occur when using both
> > format %s & %s?
> 
> The print statement understands how to directly print strings 
> (byte-strings and unicode-strings) and doesn't call your __str__ 
> method.
> 
> http://docs.python.org/reference/simple_stmts.html#the-print-statement

Right. But then how to print out customized strings?


> As for string interpolation, I have reported this as a bug:
> 
> http://bugs.python.org/issue8128

Yes, at least the actual behaviour should be clear and properly documented. And 
it should be the same for str and unicode type, and their subclasses. But I 
cannot see the advantage of not calling str(): this only prevents customization 
-- or use of string interpolation with cutomized string types.

> I have some additional comments on your class below:
> 
> 
> > class Unicode(unicode):
> > ENCODING = "utf8"
> > def __new__(self, string='', encoding=None):
> 
> This is broken according to the Liskov substitution principle.
> 
> http://en.wikipedia.org/wiki/Liskov_substitution_principle
> 
> The short summary: subclasses should only ever *add* functionality, they 
> should never take it away.
> 
> The unicode type has a function signature that accepts an encoding and 
> an errors argument, but you've missed errors.

All right, I'll have a closer look to the semantics of unicode's error arg and 
see if it makes sense in my case.

Notes for the following comments of yours:
(1) What I posted is test code written only to show the issue. (eg debug prints 
are not in the original code)
(2) This class is intended for a kind parsing and string processing library 
(think at pyparsing, but designed very differently). It should work only with 
unicode string, so convert source and every bit of string in pattern defs (eg 
for literal match). __str__ and __repr__ are intended for feedback (programmer 
test and user information, in both cases mainly error messages). __repr__ 
should normally not be used, I wrote it rather for completion.

[...] 

> > if isinstance(string,str):
> > encoding = Unicode.ENCODING if encoding is None else
> > encoding string = string.decode(encoding)
> > return unicode.__new__(Unicode, string)
> > def __repr__(self):
> > print '+',
> > return '"%s"' %(self.__str__())
> 
> This may be a problem. Why are you making your unicode class pretend to 
> be a byte-string? 

(This answer rather for __str__)
Not to pollute output. Eg parse tree nodes (= match results) show like:
integer:[sign:- digit:123]

> Ideally, the output of repr(obj) should follow this rule:
> 
> eval(repr(obj)) == obj
> 
> For instance, for built-in unicode strings:
> 
> >>> u"éâÄ" == eval(repr(u"éâÄ"))
> True

> but for your subclass, us != eval(repr(us)). So again, code that works 
> perfectly with built-in unicode objects will fail with your subclass.
> 
> Ideally, repr of your class should return a string like:
> 
> "Unicode('...')"

I 100% agree with your comment and this what I do in general. But it does not 
make much sense in my case, I guess. When I'm rather sure __repr__ will not 
normally be used, then I will probably rewrite to show Unicode("...").


> > def __str__(self):
> > print '*',
> > return '`'+ self.encode(Unicode.ENCODING) + '`'
> 
> What's the purpose of the print statements in the __str__ and __repr__ 
> methods?

Note (1).

> Again, unless you have a good reason to do different, you are best to 
> just inherit __str__ from unicode. Anything else is strongly 
> discouraged.

Note (2).

> > An issue happens in particuliar cases, when using both %s and %r:
> >
> > s = "éâÄ"
> 
> This may be a problem. "éâÄ" is not a valid str, because it contains 
> non-ASCII characters.

It's just a test case (note (1)) for non-ascii input, precisely.

> As far as I know, the behaviour of stuffing unicode characters into 
> byte-strings is not well-defined in Python, and will depend on external 
> factors like the terminal you are running in, if any. It may or may not 
> work as you expect. It is better to do this:
> 
> u = u"éâÄ"
> s = u.encode('uft-8')

Yo, but I cannot expect every user to always use only unicode everywhere as 
input to my lib (both in sources to be parsed and in pattern defs) like a 
robot. One main reason for my Unicode type (that accepts both str and unicode).
Anyway, all that source of troubles disappears with py3 :-)
Then, I only need __str__ to produce nice, clear, unpolluted output.

> which will always work consistently so long 

Re: [Tutor] First program

2010-03-13 Thread yd
Thanks everyone, I am trying to figure out functions and classes right now,
i will probably rewrite the program once i get that down and probably use
try: and except: for error catching.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Opening a dos exe

2010-03-13 Thread Ray Parrish

Emile van Sebille wrote:

On 3/10/2010 11:33 AM Armstrong, Richard J. said...

The problem comes in that the dos program requires three
inputs (input1.txt, input2.txt and input3.txt - see attached picture)
but I cannot find a way of getting this information to the dos program
from python. Any ideas?
You could use os.system("startprogram.bat"), and 
create startprogram.bat
to run the dos program, and feed it the files, 
either all at once, or
one at a time via the command line if it accepts 
command line input.


You could write out startprogram.bat 
programatically, just before you
call it, then remove it after running it to reduce 
clutter.


Hope this is what you're looking for.

Later, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, 
and articles by Ray.

http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to 
be a schizo, and other

things, including my poetry.
http://www.writingsoftheschizophrenic.com



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


Re: [Tutor] %s %r with cutom type

2010-03-13 Thread Steven D'Aprano
On Sat, 13 Mar 2010 08:40:31 pm spir wrote:

> > The print statement understands how to directly print strings
> > (byte-strings and unicode-strings) and doesn't call your __str__
> > method.
> >
> > http://docs.python.org/reference/simple_stmts.html#the-print-statem
> >ent
>
> Right. But then how to print out customized strings?

print str(obj)
print any_function_you_like(obj)

You shouldn't have objects try to lie about what they are. If a string 
is "hello" (without the quotes), then you shouldn't have it pretend to 
be "`hello`" (with quotes).


> > As for string interpolation, I have reported this as a bug:
> >
> > http://bugs.python.org/issue8128
>
> Yes, at least the actual behaviour should be clear and properly
> documented. And it should be the same for str and unicode type, and
> their subclasses. 

Which is why I have reported it as a bug.


[...]
> Notes for the following comments of yours:
> (1) What I posted is test code written only to show the issue. (eg
> debug prints are not in the original code) (2) This class is intended
> for a kind parsing and string processing library (think at pyparsing,
> but designed very differently). It should work only with unicode
> string, so convert source and every bit of string in pattern defs (eg
> for literal match). __str__ and __repr__ are intended for feedback
> (programmer test and user information, in both cases mainly error
> messages). 

What do you mean "mainly error messages"?

__str__ is intended for converting objects into a string. That's why it 
is called __str__ rather than __give_the_user_feedback__.


> __repr__ should normally not be used, I wrote it rather 
> for completion.

What do you mean, "for completion"? Unicode strings already have a 
__repr__ method. If you don't need to customize it, don't, and your 
class will inherit the existing __repr__ method.


> > This may be a problem. Why are you making your unicode class
> > pretend to be a byte-string?
>
> (This answer rather for __str__)
> Not to pollute output. Eg parse tree nodes (= match results) show
> like: integer:[sign:- digit:123]

You should keep display presentation and internal value as separate as 
possible. If your parse tree wants to display data in a particular 
format, then it is the responsibility of the parse tree to format the 
data correctly, not of the data. In fact, the parse tree itself should 
never print results. That is up to the caller: perhaps you want to 
write it to a file, print to standard out, or standard error, save it 
in a string, or anything you like.


>>> class ParseTree(object):
... def match_results(self, arg):
... return (42, "+", (1, 2), "something")
... def format_results(self, arg):
... result = self.match_results(arg)
... template = "%d: [%c:- digits:%s] `%s`"
... return template % result
...
>>> x = ParseTree().format_results(None)
>>> print x
42: [+:- digits:(1, 2)] `something`
>>> myfile.write(x + '\n')
>>>

If the Parse Tree does the printing, then the caller can't do anything 
except print.


[...]
> > > s = "éâÄ"
> >
> > This may be a problem. "éâÄ" is not a valid str, because it
> > contains non-ASCII characters.
>
> It's just a test case (note (1)) for non-ascii input, precisely.

Maybe so, but your test case depends on external factors like the 
terminal encoding. This is a bad test, because somebody else running it 
may get something completely different.


> > As far as I know, the behaviour of stuffing unicode characters into
> > byte-strings is not well-defined in Python, and will depend on
> > external factors like the terminal you are running in, if any. It
> > may or may not work as you expect. It is better to do this:
> >
> > u = u"éâÄ"
> > s = u.encode('uft-8')
>
> Yo, but I cannot expect every user to always use only unicode
> everywhere as input to my lib (both in sources to be parsed and in
> pattern defs) like a robot.

Of course you can. What happens if they pass None instead of a string? 
They get an error. What if they pass the integer 45? They get an error. 
What if they pass the list [1.235, 59.02, -267.1]? They get an error.

You are not responsible for the caller passing bad data. 

If your class relies on the user passing unicode strings, then you 
document the fact that it requires unicode strings. Then you have a 
choice:

* you can prohibit byte strings, and raise an error if they pass byte 
strings; or

* you can make a reasonable effort to convert byte strings to unicode, 
by calling encode, but if the encode() fails, oh well, that's the 
caller's responsibility.

If the user wants a string "cat" and they pass "C aT  \n" instead, 
you're not responsible for fixing their mistake. If they want the 
unicode string u"éâÄ" and they pass the byte-string "\xe9\xe2\xc4" 
instead, that's not your problem either.


> One main reason for my Unicode type (that 
> accepts both str and unicode). 

If all you want is a subclass of unicode which defaults to UTF-8 instead 
of ASC

Re: [Tutor] Opening a dos exe

2010-03-13 Thread Alan Gauld


"Ray Parrish"  wrote 


but I cannot find a way of getting this information to the dos program
from python. Any ideas?
You could use os.system("startprogram.bat"), and 
create startprogram.bat
to run the dos program, and feed it the files, 
either all at once, or one at a time via the command line if it accepts 
command line input.


I don't think you can do the second option with a bat file. There is no 
way to interactively respond to the program once it starts. Thats why 
WSH is better for that kind of interactive input.


Or just use subprocess.Popen...

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

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


Re: [Tutor] First program

2010-03-13 Thread Alan Gauld


"Luke Paireepinart"  wrote


 print "The area of a " + Choice + "is " str(Width) + " x " +
 str(Height) + " equals " + str(Width * Height) + " square 
feet"



One thing - you don't need all the str() calls in your example, print
already calls str() for you. Also comma separators are better than + 
signs



 print actually doesn't call str if you use concatenation.  So the str()
calls are necessary if you do not use "," but use "+" instead.


Good catch! - you are, of course, right. When you use + print only
sees a big single string with all the str() conversions already
done. I was thinking of the more usual comma separated
arguments to print

Alan G. 



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


[Tutor] Escaping a single quote mark in a triple quoted string.

2010-03-13 Thread Ray Parrish

Hello,

I am getting the following -

>>> String = """http://www.rayslinks.com";>Ray's Links"""
>>> String
'http://www.rayslinks.com";>Ray\'s Links'

Note the magically appearing back slash in my result string. Now I tiry 
to escape the single quote.


>>> String = """http://www.rayslinks.com";>Ray\'s Links"""
>>> String
'http://www.rayslinks.com";>Ray\'s Links'

Once again the unwanted back slash appears.

>>> NewString = """'"""
>>> NewString
"'"
Hmmm, no back slash this time...

>>> String = """http://www.rayslinks.com";>Ray""" + """'""" + 
"""s Links"""

>>> String
'http://www.rayslinks.com";>Ray\'s Links'

Why did quoting the single quote work in NewString when I triple quoted 
just the single quote, but not in the other examples where the result 
shows a back slash before my singe quote in String?


Is there a proper way to do this?

Thanks, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] Opening a dos exe

2010-03-13 Thread Ray Parrish

Alan Gauld wrote:


"Ray Parrish"  wrote

but I cannot find a way of getting this information to the dos program
from python. Any ideas?

You could use os.system("startprogram.bat"), and create startprogram.bat
to run the dos program, and feed it the files, either all at once, or 
one at a time via the command line if it accepts command line input.


I don't think you can do the second option with a bat file. There is 
no way to interactively respond to the program once it starts. Thats 
why WSH is better for that kind of interactive input.


Or just use subprocess.Popen...

OK, it was not clear to me that he needed to be interactive with the dos 
program. He just said he needed to feed those files to the dos program, 
and I assumed he meant on the command line within a dos box, which can 
indeed be solved by running a batch file, if the dos program accepts 
command line parameters..


A good tool for writing interactive scripts used to be WinBatch, but I 
haven't used, or seen it anywhere for years. It would have to be 
installed on the machine you wanted to get interactive with a dos 
program however.


I remember WinBatch from back in the Windows 3.1 days, and am not sure 
if they are still keeping it up to date.


Later, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] First program

2010-03-13 Thread Ray Parrish

Steven D'Aprano wrote:

On Sat, 13 Mar 2010 01:04:42 pm Ray Parrish wrote:
  

print "A %s with dimensions %sx%s has an area of %s." %
(choice, height, width, width*height)
  

Hello,

Isn't it a little more understandable to use a
construct like the following?



print "The area of a " + Choice + "is " str(Width) + " x " +
  

str(Height) + " equals " + str(Width * Height) + "
square feet"

The area of a rectangle is 12 x 10 equals 120
square feet.

I find that putting the variables on the end like
that, when you're not actually applying any special formatting to them
makes it less readable
when I'm debugging my stuff, or when someone else
is reading my code,
and trying to understand it.




Of course you are welcome to use whatever coding standards you like, but 
I think you will find that among experienced coders, you are in a 
vanishingly small minority. As a beginner, I found string interpolation 
confusing at first, but it soon became second-nature. And of course, 
there are legions of C coders who are used to it.


I find an expression like:

"The area of a " + Choice + "is " str(Width) + " x " + str(Height) 
+ "equals " + str(Width * Height) + "square feet"


difficult to follow: too many quotes, too many sub-expressions being 
added, too many repeated calls to str(), it isn't clear what is the 
template and what is being inserted into the template. It is too easy 
to miss a quote and get a SyntaxError, or to forget to add spaces where 
needed. To me, this is MUCH easier:


template = "The area of a %s is %s x %s equals %s square feet"
print template % (Width, Height Width*Height)

One pair of quotes instead of five, no problems with remembering to add 
spaces around pieces, and no need to explicitly call str().
  
OK, that does seem a bit easier now to me. I'm going to have to read up 
on the %s, and any other formatting % codes there are however, since I'm 
dead green in Python yet. 8-)


So, would I read about those in the string module portion of the 
documentation?


Thanks, Ray Parrish


--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] First program

2010-03-13 Thread Ray Parrish

Alan Gauld wrote:

"Ray Parrish"  wrote
print "A %s with dimensions %sx%s has an area of %s." % (choice, 
height, width, width*height)


Isn't it a little more understandable to use a construct like the 
following?


print "The area of a " + Choice + "is " str(Width) + " x " + 

str(Height) + " equals " + str(Width * Height) + " square feet"


It depends on where you come from.
Those of us brought up on C or COBOL are used to separating the 
presentation from the data. Those brought up with PASCAL and BASIC are 
used to iterleaving data with presentation.


One thing - you don't need all the str() calls in your example, print 
already calls str() for you. Also comma separators are better than + 
signs since the plus operation on strings is quite expensive - you 
create a new string for each addition.


HTH,
Thanks for the tips. If I understand you correctly I can do the call 
this way? -


print "The area of ", Choice, " is ", Width, " x ", Height, " 
equals ", (Width * Height), " square feet"


That eliminates the redundancy, and is quite readable to me. I like it. 8-)

Later, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] First program

2010-03-13 Thread Ray Parrish

Luke Paireepinart wrote:



On Sat, Mar 13, 2010 at 3:03 AM, Alan Gauld > wrote:


"Ray Parrish" mailto:c...@cmc.net>> wrote

   print "A %s with dimensions %sx%s has an area of %s." %
(choice, height, width, width*height)

Isn't it a little more understandable to use a construct like
the following?

print "The area of a " + Choice + "is " str(Width)
+ " x " +

str(Height) + " equals " + str(Width * Height) + " square feet"


It depends on where you come from.
Those of us brought up on C or COBOL are used to separating the
presentation from the data. Those brought up with PASCAL and BASIC
are used to iterleaving data with presentation.

One thing - you don't need all the str() calls in your example,
print already calls str() for you. Also comma separators are
better than + signs since the plus operation on strings is quite
expensive - you create a new string for each addition.


print actually doesn't call str if you use concatenation.  So the 
str() calls are necessary if you do not use "," but use "+" instead. 
So there are at least 2 reasons why + is worse than comma.

Another thing to be aware of is that if you use commas,
print inserts a space in the string, which may be either an advantage 
or a disadvantage depending on what you're trying to do.


-Luke
Ahhh, thank you for the clarifications. for the cases where spaces are 
needed it the commas seem like a pretty good way to do it, but when I 
need to add together stuff with no spaces I'll try the formatted method.


Thanks again, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] Escaping a single quote mark in a triple quoted string.

2010-03-13 Thread Sander Sweers
On 13 March 2010 18:33, Ray Parrish  wrote:
> Hello,
>
> I am getting the following -
>
 String = """http://www.rayslinks.com";>Ray's Links"""
 String
> 'http://www.rayslinks.com";>Ray\'s Links'
>
> Note the magically appearing back slash in my result string.

It is not really there. When you have a single quote in a single quote
string it need to be escaped with a backslash. Simulary a double quote
in a double quote string. The triple quote string does this for you.

When you write the string to a file the backslash will "magically" disappear.

> Now I tiry to escape the single quote.
>
 String = """http://www.rayslinks.com";>Ray\'s Links"""
 String
> 'http://www.rayslinks.com";>Ray\'s Links'
>
> Once again the unwanted back slash appears.

See above single quotes in single quote string need to be escaped.

 NewString = """'"""
 NewString
> "'"
> Hmmm, no back slash this time...

Correct, here you have a single quote in a double quote string.

 String = """http://www.rayslinks.com";>Ray""" + """'""" + """s
 Links"""
 String
> 'http://www.rayslinks.com";>Ray\'s Links'
>
> Why did quoting the single quote work in NewString when I triple quoted just
> the single quote, but not in the other examples where the result shows a
> back slash before my singe quote in String?
>
> Is there a proper way to do this?

You are trying to solve something that is not really a problem. What
is however is your usage of a single quote in html text. You need to
replace it with ' or ‘.

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


Re: [Tutor] First program

2010-03-13 Thread Ray Parrish

Luke Paireepinart wrote:

Ray, please reply on-list in the future in case someone else has input.

On Fri, Mar 12, 2010 at 8:01 PM, Ray Parrish > wrote:


Luke Paireepinart wrote:

   print "A %s with dimensions %sx%s has an area of %s." %
(choice, height, width, width*height)


Isn't it a little more understandable to use a construct like the
following?

>>> print "The area of a " + Choice + "is " str(Width) + " x " +
str(Height) + " equals " + str(Width * Height) + " square feet"

The area of a rectangle is 12 x 10 equals 120 square feet.

I find that putting the variables on the end like that, when
you're not actually applying any special formatting to them makes
it less readable when I'm debugging my stuff, or when someone else
is reading my code, and trying to understand it.


Your version creates at least 10 intermediate strings before outputting.
Remember strings are immutable in Python. 
So you're constructing strings

The area of a
The area of a rectangle
The area of a rectangle is
12
The area of a rectangle is 12
The area of a rectangle is 12 x
10
The area of a rectangle is 12 x 10
The area of a rectangle is 12 x 10 equals
120
The area of a rectangle is 12 x 10 equals 120
The area of a rectangle is 12 x 10 equals 120 square feet

With string formatting you avoid all of these intermediate strings, so 
it's arguably more efficient.
Other than just viewing from a performance standpoint though, I find 
it much easier to read my version, because any computation required 
takes place at the end of the line.
For example, your inline str(width*height) requires you to read the 
whole line to see it.


It's really a personal thing, it's easier for me to read the 
formatting version than the string concatenation version, in most cases.
Now if you had used the comma convention I would have seen your 
point.  This is, I think, the easiest to read of all 3

area = width * height
print "The area of a", choice, "is", width, "x", height, ", which 
equals", area, "square feet."


Also, why are you capitalizing variable names?  That's a pretty 
unusual convention.


-Luke
Thanks for letting me know how inefficient my method is. I'll remember 
that, and apply your suggestions to my code from now on. So, you're 
saying that the commas method also does not suffer from the overhead of 
creating a bunch of individual strings?


As far as the capitalizations, it's just a habit I've held over from my 
Visual Basic days, and earlier programming. It's a little easier for me 
to pick out the individual words in a variable like ThisPerson as 
opposed to thisperson. I have been made aware that Python standard 
coding practice requires lower case variable names, and as soon as I can 
force myself to do it that way, or can remember to post that way I will 
be adopting the in place standards and conventions.


Is it actually supposed to be this_person? I read part of the standards 
document, but can not remember right off the top of my head if 
underlines between words is required.


Thanks, Ray Parrish



--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] Escaping a single quote mark in a triple quoted string.

2010-03-13 Thread Steven D'Aprano
On Sun, 14 Mar 2010 04:33:57 am Ray Parrish wrote:
> Hello,
>
> I am getting the following -
>
>  >>> String = """http://www.rayslinks.com";>Ray's Links"""
>  >>> String
> 'http://www.rayslinks.com";>Ray\'s Links'
>
> Note the magically appearing back slash in my result string.

You are confusing the printed representation of the string with the 
contents of the string. The backslash is not part of the string, any 
more than the leading and trailing quotes are part of the string. They 
are part of the display of the string.

Consider:

>>> s = "ABC"  # Three characters A B C.
>>> s  # Looks like five?
'ABC'
>>> len(s)  # No, really only three.
3

The quotes are not part of the string, but part of the printable 
representation. This is supposed to represent what you would type to 
get the string ABC. You have to type (quote A B C quote).

Now consider:

>>> s = """A"'"B"""  # Five chars A double-quote single-quote d-quote B
>>> s  # Looks like eight?
'A"\'"B'
>>> len(s)  # But actually only five.
5

When printing the representation of the string, Python always wraps it 
in quotation marks. If the contents include quotation marks as well, 
Python will escape the inner quotation marks if needed, but remember 
this is only for the display representation. If you want to see what 
the string looks like without the external quotes and escapes:

>>> print s
A"'"B


>  >>> NewString = """'"""
>  >>> NewString
>
> "'"
> Hmmm, no back slash this time...

In this case, the string itself only contains a single-quote, no 
double-quote, so when showing the representation, Python wraps the 
contents with double-quotes and there is no need to escape the 
single-quote.

Python's rules for showing the representation of the string includes:

* wrap the string contents in single quotes '
* unless the string contains single quotes, in which case wrap it 
  in double quotes " and display the single quotes unescaped
* unless the string contains double quotes as well, in which case 
  wrap it in single quotes and escape the inner single quotes.

But remember: this is only the display of the string, not the contents.



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


Re: [Tutor] First program

2010-03-13 Thread Ray Parrish

Andre Engels wrote:

On Sat, Mar 13, 2010 at 3:11 AM, Ray Parrish  wrote:
  

Andre Engels wrote:


On 3/12/10, yd  wrote:
  

 else:
   raise Exception('{0}, is not a valid choice'.format(choice))



This will cause the program to stop-with-error if something wrong is
entered. I think that's quite rude. I would change this to:
 else:
   print('{0}, is not a valid choice'.format(choice))

  

Here's what I get from that, could you please explain why?



You're probably using Python 2.4 or 2.5; the .format method has been
introduced in Python 2.6, and is considered the 'standard' way of
working in Python 3. For older Python versions, this should read

print('%s, is not a valid choice'%(choice))
  
Yes, I'm using 2.45.2 as that is the highest version available in the 
Ubuntu repositories, and I'd like to keep it simple for users of 
programs i write. If I install a higher version from somewhere other 
than the repositories it will force users of my programs to do the same, 
and the repositories are the trusted source of software for Ubuntu, and 
other Linux users.


Thanks for being so observant.

Later, Ray Parrish
--

Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] Escaping a single quote mark in a triple quoted string.

2010-03-13 Thread Ray Parrish

Sander Sweers wrote:

On 13 March 2010 18:33, Ray Parrish  wrote:
  

Hello,

I am getting the following -



String = """http://www.rayslinks.com";>Ray's Links"""
String
  

'http://www.rayslinks.com";>Ray\'s Links'

Note the magically appearing back slash in my result string.



It is not really there. When you have a single quote in a single quote
string it need to be escaped with a backslash. Simulary a double quote
in a double quote string. The triple quote string does this for you.

When you write the string to a file the backslash will "magically" disappear.

  

Now I tiry to escape the single quote.



String = """http://www.rayslinks.com";>Ray\'s Links"""
String
  

'http://www.rayslinks.com";>Ray\'s Links'

Once again the unwanted back slash appears.



See above single quotes in single quote string need to be escaped.

  

NewString = """'"""
NewString
  

"'"
Hmmm, no back slash this time...



Correct, here you have a single quote in a double quote string.

  

String = """http://www.rayslinks.com";>Ray""" + """'""" + """s
Links"""
String
  

'http://www.rayslinks.com";>Ray\'s Links'

Why did quoting the single quote work in NewString when I triple quoted just
the single quote, but not in the other examples where the result shows a
back slash before my singe quote in String?

Is there a proper way to do this?



You are trying to solve something that is not really a problem. What
is however is your usage of a single quote in html text. You need to
replace it with ' or ‘.

Greets
Sander
  
Thanks for your quick answer. I'll accept that there will not be a back 
slash in my file when I write it then.


I was not aware that single quotes were bad news in HTML. I don't think 
I've ever experienced a problem using them myself, but will adjust, and 
start using the & code for it instead.


Later, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


[Tutor] Problem with little program

2010-03-13 Thread Marco Rompré
Hello I have a little problem, I am trying to define a function ligneCar(n,
ca) that would print n times the caracters ca.
For now I have the user entering a short sentence corresponding to ca.

Here is my code:

def ligneCar(n,ca):
c=0
while c___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First program

2010-03-13 Thread Alan Gauld


"Ray Parrish"  wrote 

As far as the capitalizations, it's just a habit I've held over from my 
Visual Basic days, and earlier programming. It's a little easier for me 
to pick out the individual words in a variable like ThisPerson as 
opposed to thisperson. 


thisPerson is fine for a variable

ThisPerson implies to most Python progranmmers that it's a class.

Is it actually supposed to be this_person? 


I think the official style guide says use underscores, 
I personally prefer the this{erson stule except where it 
is ambiguous. Underscores have the adbvantage of 
never being ambiguous - but they do involve extra typing...


Alan G.

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


Re: [Tutor] Problem with little program

2010-03-13 Thread Alan Gauld


"Marco Rompré"  wrote


def ligneCar(n,ca):
   c=0
   while c

The bottom two lines are not part of the function, they will
be executed when you import the file - is that really what you wantr?


then in another python file

I want to recall my function ligne_Car but it is not working.


So show us the code that is not working!
How are you importing the function? How are you accessing it?
What error message do you get, if any?
What happens?


Please help me


Please help us.
We can't possibly guess what you might be doing wrong
with no clues.

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



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


Re: [Tutor] First program

2010-03-13 Thread Ken G.

I am using Ubuntu 9.04 and I have versions 2.6.2 and 3.0.1+ installed.

Look for IDLE in Add/Remove Applications. 


Perhaps, you may have a different version of Ubuntu.

Ken

Ray Parrish wrote:
 
Yes, I'm using 2.45.2 as that is the highest version available in the 
Ubuntu repositories, and I'd like to keep it simple for users of 
programs i write. If I install a higher version from somewhere other 
than the repositories it will force users of my programs to do the 
same, and the repositories are the trusted source of software for 
Ubuntu, and other Linux users.


Thanks for being so observant.

Later, Ray Parrish

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


Re: [Tutor] First program

2010-03-13 Thread Luke Paireepinart
On Sat, Mar 13, 2010 at 12:04 PM, Ray Parrish  wrote:

> Luke Paireepinart wrote:
>
>>
>> Your version creates at least 10 intermediate strings before outputting.
>> Remember strings are immutable in Python. So you're constructing strings
>> The area of a
>> The area of a rectangle
>> The area of a rectangle is
>> 12
>> The area of a rectangle is 12
>> The area of a rectangle is 12 x
>> 10
>> The area of a rectangle is 12 x 10
>> The area of a rectangle is 12 x 10 equals
>> 120
>> The area of a rectangle is 12 x 10 equals 120
>> The area of a rectangle is 12 x 10 equals 120 square feet
>>
>> With string formatting you avoid all of these intermediate strings, so
>> it's arguably more efficient.
>> Other than just viewing from a performance standpoint though, I find it
>> much easier to read my version, because any computation required takes place
>> at the end of the line.
>> For example, your inline str(width*height) requires you to read the whole
>> line to see it.
>>
>> It's really a personal thing, it's easier for me to read the formatting
>> version than the string concatenation version, in most cases.
>> Now if you had used the comma convention I would have seen your point.
>>  This is, I think, the easiest to read of all 3
>> area = width * height
>> print "The area of a", choice, "is", width, "x", height, ", which equals",
>> area, "square feet."
>>
>> Also, why are you capitalizing variable names?  That's a pretty unusual
>> convention.
>>
>

>  Thanks for letting me know how inefficient my method is. I'll remember
> that, and apply your suggestions to my code from now on. So, you're saying
> that the commas method also does not suffer from the overhead of creating a
> bunch of individual strings?
>


Yes, the 'comma method' is actually doing something sorta tricky behind the
scenes: it's creating a tuple and passing it to print.
Look what happens when you just comma-separate stuff normally:
>>> 'hello','how','are','you?'
('hello', 'how', 'are', 'you?')

This implicit tuple conversion is useful in other situations too:
>>> a, b = 1 , 2
>>> a
1
>>> b
2

this is creating the tuple (1,2) and then iterating over the tuple and
assigning values to whatever's on the left hand side (a, b in this case).
And you can abuse it if you really want to, to force things into tuples:
>>> a,
(1,)


So what's happening when you call print with the tuple, is that print is
basically doing this behind the scenes:
for item in tuple:
sys.stdout.write(item)
sys.stdout.write(" ")
sys.stdout.write("\n")

Of course it doesn't do this in Python but rather in C, at a lower level,
but that is basically the idea.
If print gets a list or a tuple of strings it will iterate over them and
output them to standard out with spaces.  This doesn't incur the string
concatenation overhead.


Truthfully, the penalty for concatenating strings is not that big, the
reason most people don't use the + method is just because they find it
harder to read/follow.
Or, I should say: the penalty for concatenating strings _that you're going
to output_ is not that big, because you tend to output short strings and not
a lot of them,
otherwise the output is pretty much unreadable.

If you do something like this:
x = ""
for i in range(100):
x += str(i) + " "

You'd probably want to change it to
y = []
for i in range(100):
y.append(i)
x = " ".join(map(y, str))

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


Re: [Tutor] First program

2010-03-13 Thread Ray Parrish

Ken G. wrote:

I am using Ubuntu 9.04 and I have versions 2.6.2 and 3.0.1+ installed.

Look for IDLE in Add/Remove Applications.
Perhaps, you may have a different version of Ubuntu.

Ken

Ray Parrish wrote:
 
Yes, I'm using 2.45.2 as that is the highest version available in the 
Ubuntu repositories, and I'd like to keep it simple for users of 
programs i write. If I install a higher version from somewhere other 
than the repositories it will force users of my programs to do the 
same, and the repositories are the trusted source of software for 
Ubuntu, and other Linux users.


Thanks for being so observant.

Later, Ray Parrish
That should have been version 2.5.2 without the 4 I typoed. I'm using 
Hardy Heron, 8.04, and plan to stick with it until version 10 comes out 
as it is the next LTS version.


I'm eyeballing Idle in Synaptic, and it appears to be an IDE for version 
2.5 of Python for my version of Ubuntu. Idle is available for version 
2.4 there as well. I'm pretty used to writing all of my code with only 
the aid of syntax highlighting, but have been hankering for an editor 
that will allow tabbed, or collapsible functions, and collapsible block 
elements.


Does Idle do that? I guess I'll just go ahead and install it, and give 
it a try. Some IDEs I don't like with their project centric viewpoint, 
and my inability to quickly absorb their project file structures details 
to the point I can use them.


If that doesn't happen pretty much within ten or fifteen minutes I go 
back to gedit. 8-)


Later, Ray Parrish


--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] Escaping a single quote mark in a triple quoted string.

2010-03-13 Thread Ray Parrish

Steven D'Aprano wrote:

On Sun, 14 Mar 2010 04:33:57 am Ray Parrish wrote:
  

Hello,

I am getting the following -

 >>> String = """http://www.rayslinks.com";>Ray's Links"""
 >>> String
'http://www.rayslinks.com";>Ray\'s Links'

Note the magically appearing back slash in my result string.



You are confusing the printed representation of the string with the 
contents of the string. The backslash is not part of the string, any 
more than the leading and trailing quotes are part of the string. They 
are part of the display of the string.


Consider:

  

s = "ABC"  # Three characters A B C.
s  # Looks like five?


'ABC'
  

len(s)  # No, really only three.


3

The quotes are not part of the string, but part of the printable 
representation. This is supposed to represent what you would type to 
get the string ABC. You have to type (quote A B C quote).


Now consider:

  

s = """A"'"B"""  # Five chars A double-quote single-quote d-quote B
s  # Looks like eight?


'A"\'"B'
  

len(s)  # But actually only five.


5

When printing the representation of the string, Python always wraps it 
in quotation marks. If the contents include quotation marks as well, 
Python will escape the inner quotation marks if needed, but remember 
this is only for the display representation. If you want to see what 
the string looks like without the external quotes and escapes:


  

print s


A"'"B


  

 >>> NewString = """'"""
 >>> NewString

"'"
Hmmm, no back slash this time...



In this case, the string itself only contains a single-quote, no 
double-quote, so when showing the representation, Python wraps the 
contents with double-quotes and there is no need to escape the 
single-quote.


Python's rules for showing the representation of the string includes:

* wrap the string contents in single quotes '
* unless the string contains single quotes, in which case wrap it 
  in double quotes " and display the single quotes unescaped
* unless the string contains double quotes as well, in which case 
  wrap it in single quotes and escape the inner single quotes.


But remember: this is only the display of the string, not the contents.
  
Thank you, that was a very concise description, and has aided my 
comprehension greatly. Now if I can just keep it separate from the 
syntax in JavaScript, I'll be doing good. I keep a good record of these 
forum posts, so I can re-read this if necessary.


Later, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


[Tutor] Declaring a compound dictionary structure.

2010-03-13 Thread Ray Parrish

Hello,

I am stuck on the following -

   # Define the Dates{} 
dictionary structure as a dictionary
   # containing two dictionaries, 
each of which contains a list.
   Dates = 
{Today:{ThisIPAddress:[]}, 
Tomorrow:{ThisIPAddress:[]}}


How do I pass this declaration empty values for 
Today, Tomorrow, and ThisIPAddress to initially 
clare it? I have managed to pass it [] as an empty 
list, but passing # "" as an empty dictionary 
label does not work correctly.


 Dates = {"":"":[]}, "":{"":[]}}

The above is what I tried, and that creates a 
dictionary with index values of "" for all of the 
key values from the previous declaration. Is there 
a way to create this comound dictionary structure 
with no key values defined at all to begin with? 
The reason I'd like to know is that with the 
second declaration the "" indexed keys  have to be 
removed after assigning at least one key value 
with a non-blank name.


The idea behind the structure is to sort through a 
server log that contains entries for two dates, 
collecting a pair of dictionaries of ip address 
indexed server log lines which can then be 
iterated over to
extract daily visit counts, and other extractable 
data sorted by date, and visitor.


The need would not arise if the log files did not 
contain two dates each, but my service provider 
rotates their server logs around 2 am, so I always 
get a few entries for the next day in every log file.


Thanks, Ray Parrish


--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, 
and articles by Ray.

http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to 
be a schizo, and other

things, including my poetry.
http://www.writingsoftheschizophrenic.com



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


Re: [Tutor] Problem with little program

2010-03-13 Thread C M Caine
That's an easy mistake to make. Simply use raw_input instead of input.
The former will always return a string, the latter treats whatever you
enter as executable python code.

You almost never want to use input. raw_input is safer.

On 13 March 2010 18:56, Marco Rompré  wrote:
>
> Hello I have a little problem, I am trying to define a function ligneCar(n, 
> ca) that would print n times the caracters ca.
> For now I have the user entering a short sentence corresponding to ca.
> Here is my code:
> def ligneCar(n,ca):
>     c=0
>     while c         print ca
>         c+=1
> ca = input ('Enter a short phrase : ')
> n = input ('Enter how many times you want  : ')
> Thats the definition of my function ligne_Car
> then in another python file
> I want to recall my function ligne_Car but it is not working.
> Please help me
>
>
> --
> Marc-O. Rompré
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Declaring a compound dictionary structure.

2010-03-13 Thread Steven D'Aprano
On Sun, 14 Mar 2010 10:06:49 am Ray Parrish wrote:
> Hello,
>
> I am stuck on the following -
>
> # Define the Dates{}
> dictionary structure as a dictionary
> # containing two dictionaries,
> each of which contains a list.
> Dates =
> {Today:{ThisIPAddress:[]},
> Tomorrow:{ThisIPAddress:[]}}
>
> How do I pass this declaration empty values for
> Today, Tomorrow, and ThisIPAddress to initially
> clare it? 

You don't. Once you create a key, you can't modify it. So if you create 
an empty value for Today etc., it stays empty. 


> The idea behind the structure is to sort through a
> server log that contains entries for two dates,
[...]

Just work out the dates before hand, and populate the dictionary that 
way:

today = "2010-03-13"
tomorrow = "2010-03-14"
thisIP = "123.456.789.123"
entries = {today: {thisIP: []}, tomorrow: {thisIP: []}}

Or don't pre-populate the dict at all.

entries = {}
for line in logfile:
# Process the line to get a date, an IP address, and visitor
date = ...
address = ...
visitor = ...
entry = entries.get(date, {})
x = entry.get(address, {})
x.append(visitor)
entry[address] = x
entries[date] = entry



The trick is to use get to look up the dictionary:

entries.get(date, {})

looks up date in entries, and if it isn't found, it returns an empty 
dict {} instead of failing. Similarly for looking up the IP address.



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


Re: [Tutor] Problem with little program

2010-03-13 Thread Alan Gauld


"C M Caine"  wrote


That's an easy mistake to make. Simply use raw_input instead of input.
The former will always return a string, the latter treats whatever you
enter as executable python code.


Whilst I agree with the general principle to use raw_input, I don't
see how we can say that it is the problem here. Indeed so far as
I can tell we don't even know what the problem here is other than
that the OP is trying to call the function he has defined in
another file.


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


On 13 March 2010 18:56, Marco Rompré  wrote:


Hello I have a little problem, I am trying to define a function 
ligneCar(n, ca) that would print n times the caracters ca.

For now I have the user entering a short sentence corresponding to ca.
Here is my code:
def ligneCar(n,ca):
c=0
while c


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