Re: [Tutor] Printing with no newline :(

2011-11-06 Thread Sarma Tangirala
On 6 November 2011 13:11, Peter Otten <__pete...@web.de> wrote:

> Joe Batt wrote:
>
> > I am learning Python 3 and programming and am very new so please bear
> with
> > me…
> > I am writing a program to pull out specific characters in a sequence and
> > then print then out. So far so good however when the characters are
> > printed out they pint on separate lines as opposed to what I want, all on
> > the same line. I have tried \n and just ,  in the pint statement i.e.
> > print(letterGroup[4],) and print(letterGroup[4]\n) and even
> > print(letterGroup[4],/n)…….. Can anyone help and explain please….Thank
> you
>
> The following arrived in a totally messed up formatting:
>
> > for line in file:
> > m = re.search(regexp, line)
> > if m:
> > letterGroup = m.group(0)
> > print(letterGroup[4])
>
> You can specify what to print after the argument(s) with the end keyword
> parameter:
>
> >>> items = 1, 2, 3
> >>> for item in items:
> ... print(item, end=" ")
> ...
> 1 2 3 >>>
> >>> for item in items:
> ... print(item, end="")
> ...
> 123>>>
> >>> for item in items:
> ... print(item, end="WHATEVER")
>


Another way of writing the above.

for i in items:
 print item[i], "whatever", "\n"


...
> 1WHATEVER2WHATEVER3WHATEVER>>>
>
> The default for end is of course newline, spelt "\n" in a Python string
> literal. Use
>
> >>> help(print)
>
> in the interactive interpreter to learn more about the print() function.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing with no newline :(

2011-11-06 Thread Sarma Tangirala
On 6 November 2011 15:47, Dave Angel  wrote:

> On 11/06/2011 04:45 AM, Sarma Tangirala wrote:
>
>> On 6 November 2011 13:11, Peter Otten<__pete...@web.de>  wrote:
>>
>>  Joe Batt wrote:
>>>
>>>  I am learning Python 3 and programming and am very new so please bear
>>>>
>>> 
>>>
>>>  for item in items:
>>>>>>
>>>>> ... print(item, end="WHATEVER")
>>>
>>>
>> Another way of writing the above.
>>
>> for i in items:
>>  print item[i], "whatever", "\n"
>>
>>
>>  Nope. That would put a newline between each iteration, which is
> explicitly what the OP did not want.  More importantly, it'd give a syntax
> error in Python 3, which the OP carefully specified.
>
> --
>
> DaveA
>
>

I'm sorry. Didn't notice the python 3 part, I just joined the list and did
not look at the OPs post. Sorry about that.

Please bear with me on this, but does the following not print "end" for
every iteration of "items"?

for item in items:
 print(item, end="")




-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing with no newline :(

2011-11-06 Thread Sarma Tangirala
I am so very sorry for the noise. I was careless in reading the OPs post.

On 6 November 2011 15:53, Sarma Tangirala  wrote:

>
>
> On 6 November 2011 15:47, Dave Angel  wrote:
>
>> On 11/06/2011 04:45 AM, Sarma Tangirala wrote:
>>
>>> On 6 November 2011 13:11, Peter Otten<__pete...@web.de>  wrote:
>>>
>>>  Joe Batt wrote:
>>>>
>>>>  I am learning Python 3 and programming and am very new so please bear
>>>>>
>>>> 
>>>>
>>>>  for item in items:
>>>>>>>
>>>>>> ... print(item, end="WHATEVER")
>>>>
>>>>
>>> Another way of writing the above.
>>>
>>> for i in items:
>>>  print item[i], "whatever", "\n"
>>>
>>>
>>>  Nope. That would put a newline between each iteration, which is
>> explicitly what the OP did not want.  More importantly, it'd give a syntax
>> error in Python 3, which the OP carefully specified.
>>
>> --
>>
>> DaveA
>>
>>
>
> I'm sorry. Didn't notice the python 3 part, I just joined the list and did
> not look at the OPs post. Sorry about that.
>
> Please bear with me on this, but does the following not print "end" for
> every iteration of "items"?
>
> for item in items:
>  print(item, end="")
>
>
>
>
> --
> Sarma Tangirala,
> Class of 2012,
> Department of Information Science and Technology,
> College of Engineering Guindy - Anna University
>
>


-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing with no newline :(

2011-11-06 Thread Sarma Tangirala
On 6 November 2011 16:57, Dave Angel  wrote:

> On 11/06/2011 05:23 AM, Sarma Tangirala wrote:
>
>> 
>>
>
>   I just joined the list and did
>>
>
> WELCOME to the list.  I should have said that first.
>
> --
>
> DaveA
>
>
Ha! Sorry for the noise again!

-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing with no newline :(

2011-11-07 Thread Sarma Tangirala
On 6 November 2011 21:09, Alan Gauld  wrote:

> On 06/11/11 10:23, Sarma Tangirala wrote:
>
>  I'm sorry. Didn't notice the python 3 part, I just joined the list and
>> did not look at the OPs post. Sorry about that.
>>
>
> welcome to the list :-)
>
>
>  Please bear with me on this, but does the following not print "end" for
>> every iteration of "items"?
>>
>> for item in items:
>>  print(item, end="")
>>
>
> No, end is a new optional parameter for the print function in Python 3.
> Recall that in Python2 print was a command whereas in Python 3 it is a
> function which has a couple of new options:
>
>
Thank you!


> ---
> Help on built-in function print in module builtins:
>
> print(...)
>print(value, ..., sep=' ', end='\n', file=sys.stdout)
>
>Prints the values to a stream, or to sys.stdout by default.
>Optional keyword arguments:
>file: a file-like object (stream); defaults to the current sys.stdout.
>sep:  string inserted between values, default a space.
>end:  string appended after the last value, default a newline.
>
>
>
> --
> Alan G
> 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<http://mail.python.org/mailman/listinfo/tutor>
>




-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character ?

2011-11-20 Thread Sarma Tangirala
Would the html parser library in python be a better idea as opposed to
using split? That way you have greater control over what is in the html.
On 20 Nov 2011 23:58, "dave selby"  wrote:

> Hi All,
>
> I have a long string which is an HTML file, I strip the HTML tags away
> and make a list with
>
> text = re.split('<.*?>', HTML)
>
> I then tried to search for a string with text.index(...) but it was
> not found, printing HTML to a terminal I get what I expect, a block of
> tags and text, I split the HTML and print text and I get loads of
>
> \x00T\x00r\x00i\x00a\x00  ie I get \x00 breaking up every character.
>
> Any idea what is happening and how to get back to a list of ascii strings ?
>
> Cheers
>
> Dave
>
> --
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
> ___
> Tutor maillist  -  Tutor@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] why doesn't python show error

2011-11-28 Thread Sarma Tangirala
On 28 November 2011 15:23, surya k  wrote:

>
> 1. Why doesn't python show error(description given below) at
> the beginning when we use functions which aren't present in the standard
> modules...
>
> Example:
>
> TheString = raw_input('enter a string')lengthofStr = strlen(TheString)Look
> closely, I used a wrong function to find length of the string. [ strlen( )
> belongs to C ].When I run the program, it didn't show any error but when
> entered input, it then showed up!.Why python doesn't show error at the
> beginning just like C does?2. Why doesn't python create executable file
> (.exe ) when we run the code.. If this doesn't do, how can I share my
> program.. does everyone need to have python to check others code and know
> what it does?
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


The thing is, python does not compile code like C does. It interprets each
line. So as you say, "it runs". Errors turn up only when they are
encountered.

http://en.wikipedia.org/wiki/Interpreted_language

But python does have a compile version, I believe jython does this.

There are a couple of programs that generate executable, py2exe on Win for
example.

http://stackoverflow.com/questions/2933/an-executable-python-app


-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Saved the Day

2011-12-04 Thread Sarma Tangirala
We shoud have a new tag say [Superman Python] for posts like these. :D
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What style do you call Python programming?

2011-12-09 Thread Sarma Tangirala
On 9 December 2011 20:07, Cranky Frankie  wrote:

> I'm looking for a term to call the kind of Python programming that
> Python is, in other words, programming with no branching, no GOTOs, no
> statement labels and no line numbers. I'm tempted to call it
> Structured Progamming, but we had that in COBOL, and this is not like
> COBOL.
>
>
The keyword you are looking for is 'programming paradigm' and python
implements several and not just any specific one such as structured. You
could call it a multi-paradigm programming language.

http://en.wikipedia.org/wiki/Programming_paradigm


> It seems to be with Python the whole thing is creating functions and
> then using loops, with an occasional BREAK or CONTINUE, to control
> program flow. I know it's Structured, but it's not like COBOL
> structured, if you know what I mean.
>
>
The point is its a scripted language. Most of what you want to do should be
about a line. Python is derived from the idea of scripted languages wherein
constructs like loops and functions were added for more control. The main
idea of programming in python is not essentially writing a functions but
rather like shell scripting, one line of syntax at a time. Having
functions, for example, gives you greater control or rather an abstraction
of control for clarity of thought.

I hope this is clear enough.
>
> --
> Frank L. "Cranky Frankie" Palmeri
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What style do you call Python programming?

2011-12-09 Thread Sarma Tangirala
On 9 December 2011 20:50, Dario Lopez-Kästen  wrote:

> On Fri, Dec 9, 2011 at 3:54 PM, Sarma Tangirala  > wrote:
>
>>
>> On 9 December 2011 20:07, Cranky Frankie wrote:
>>
>>> I'm looking for a term to call the kind of Python programming that
>>>
>>> <...snip...>
>
>>
>>>
>> The keyword you are looking for is 'programming paradigm' and python
>> implements several and not just any specific one such as structured. You
>> could call it a multi-paradigm programming language.
>>
>> http://en.wikipedia.org/wiki/Programming_paradigm
>>
>> <...snip..>
>
>> The point is its a scripted language. Most of what you want to do should
>> be about a line. Python is derived from the idea of scripted languages
>> wherein constructs like loops and functions were added for more control.
>> The main idea of programming in python is not essentially writing a
>> functions but rather like shell scripting, one line of syntax at a time.
>> Having functions, for example, gives you greater control or rather an
>> abstraction of control for clarity of thought.
>>
>>
> I actually don't agree at all with your last statements. Since you quote
> Wikipedia, allow me to do the same:
>
> http://en.wikipedia.org/wiki/Python_(programming_language)
> *
> *
>
>> *"Python supports multiple programming paradigms, primarily but not
>> limited to object-oriented, imperative and, to a lesser extent, functional
>> programming styles. It features a fully dynamic type system and
>> automatic memory management, similar to that of Scheme, Ruby, Perl,
>> and Tcl. Like other dynamic languages, Python is often used as a scripting
>> language, but is also used in a wide range of non-scripting contexts. Using
>> third-party tools, Python code can be packaged into standalone executable
>> programs. Python interpreters are available for many operating systems."*
>
>
> Keywords, IMHO are: imperative, object oriented, interpreted dynamic
> programming language. Scripting comes as a bonus of the fact that it is
> interpreted.
>
> My 0.02€
>

Where does it say that python was originally not designed to be scripted?
If thats the case then I agree my comment was completely incorrect. I read
somewhere that it was designed so. I don't get exactly where you disagree
with me as I wrote that part about scripting for the second paragraph.

With respect to the OP's question how does being imperative, OO or dynamic
determine "I'm looking for a term to call the kind of Python programming
that
Python is, in other words, programming with no branching, no GOTOs, no
statement labels and no line numbers."?


>
> /dario
>
>


-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What style do you call Python programming?

2011-12-09 Thread Sarma Tangirala
On 9 December 2011 21:44, Steven D'Aprano  wrote:

> Sarma Tangirala wrote:
>
>  The point is its a scripted language.
>>
>
> Define "scripted language". (Scripting language?)
>
>
>
I meant scripting language. :)


>
>  Most of what you want to do should be
>> about a line. Python is derived from the idea of scripted languages
>> wherein
>> constructs like loops and functions were added for more control.
>>
>
> I don't understand what you mean by "should be about a line". If your idea
> is that Python is an interpreter that reads the source code line by line,
> interpreting then executing each one in turn, you couldn't be more wrong.
> Python uses a compiler that generates byte-code, then executes it in a
> virtual machine, just like (for example) Java. The CPython compiler and
> virtual machine is the reference implementation; the PyPy implementation is
> a JIT compiler which can approach the speed of optimized C code, and in a
> very few cases, actually beat it.
>
>
Well, what I meant was the way you write things like list comprehension. I
agree, that comment gave a completely incorrect picture. Sorry about that.


> If Python is a "scripting language", it is a scripting language which can
> perform video processing on the fly:
>
> http://morepypy.blogspot.com/**2011/07/realtime-image-**
> processing-in-python.html<http://morepypy.blogspot.com/2011/07/realtime-image-processing-in-python.html>
>
>
>
Scripting language not in the true sense. My bad.


>
>  The main
>> idea of programming in python is not essentially writing a functions but
>> rather like shell scripting, one line of syntax at a time.
>>
>
> I can't imagine why you think that is the "main idea" for programming in
> Python. Even in true scripting languages like bash, the use of functions is
> strongly recommended. For anything but the simplest script, you are better
> off encapsulating code into functions or classes.
>
> Of course Python can be used to write simple scripts without functions.
> And complex scripts with functions. And "glue" code to interface between
> libraries written in C or Fortran. And major applications with tens or
> hundreds of thousands of lines of code, dozens of modules, hundreds of
> classes and functions. And everything in between.
>
>
>
I disagree here. Writing bigger pieces of code warrant the use of functions
not the other way around. What I was trying to say was that in C you'd have
to use a main function and in Java a public class in your code. In python
it is not a business of using functions as the OP had mentioned.  As to the
"main idea", I think I could have worded that a bit better.

I'm really sorry if what I posed before was annoying crap. :)


>
> --
> Steven
>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] best book for OOP

2011-12-12 Thread Sarma Tangirala
> Object Oriented Analysis and Design with Applications
> by Grady Booch (1st edition)
> Classic text on OO Design with code and case studies realized in 5
different OOP languages (Smalltalk, Object Pascal, C++, Lisp, ADA)
> Explains why OOP is important and how to ise it effectively. Also
introsduces Booch's OOD notation which was paret of the core that evolved
into UML.
>

+1
Used this book in an OOAD course and was very good.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reset password program

2011-12-16 Thread Sarma Tangirala
> thanks dave,
> just tried writing to file for the first time
>
> def main():
>  outfile.write('Hello this is a test')
>  outfile.close()
> main()
>
> error, globalname outfile is not defined, do i need to import function to
get this working?
>
>

Fyi, you should check the python docs. They have a good introduction if
this is the first time. Also its a good idea to use a try block incase the
file does not exist and you have to do a bit of error handling.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Sorting Nested Lists

2012-01-09 Thread Sarma Tangirala
Hi list,

I was banging my head about a pythonic way of doing the following,

Given a nested list, how do I sort the uppermost list based on one key and
when a special condition occurs a sort on another key should be performed?

For example, [[1,2], [2, 2], [3, 2], [4, 0]] would be sorted, in my example
as, [[4, 0], [3, 2], [2, 2], [1, 2]]. That is, sort on the second value and
in case they are equal, reverse sort on the first value.

I tried doing this using sorted and using a custom cmp function but not
sure about how to define the cmp function.

-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sorting Nested Lists

2012-01-09 Thread Sarma Tangirala
On 9 January 2012 18:26, Steven D'Aprano  wrote:

> Sarma Tangirala wrote:
>
>> Hi list,
>>
>> I was banging my head about a pythonic way of doing the following,
>>
>> Given a nested list, how do I sort the uppermost list based on one key and
>> when a special condition occurs a sort on another key should be performed?
>> For example, [[1,2], [2, 2], [3, 2], [4, 0]] would be sorted, in my
>> example
>> as, [[4, 0], [3, 2], [2, 2], [1, 2]]. That is, sort on the second value
>> and
>> in case they are equal, reverse sort on the first value.
>>
>
> That is not exactly a good example. There are at least two other ways to
> get the result you show, both much more obvious:
>
> py> L = [[1,2], [2, 2], [3, 2], [4, 0]]
> py> list(reversed(L))
>
> [[4, 0], [3, 2], [2, 2], [1, 2]]
> py> sorted(L, reverse=True)
>
> [[4, 0], [3, 2], [2, 2], [1, 2]]
>
>
> If I ignore your example, and just use the description:
>
> "sort on the second value, and in case they are equal, reverse sort on the
> first value"
>
> the way to do this is with a double sort. Note that this works because
> Python's sort is stable: in the event of ties, the first item remains
> first. In earlier versions of Python, this was not always the case.
>
> So, given this list:
>
> L = [[1,2], [4,0], [3,2], [2,2], [5,1], [1,1]]
>
> first sort in reverse by the first item, then by the second:
>
>
> py> L.sort(key=lambda sublist: sublist[0], reverse=True)
> py> L.sort(key=lambda sublist: sublist[1])
> py> print L
> [[4, 0], [5, 1], [1, 1], [3, 2], [2, 2], [1, 2]]
>
>
>
> Note that using a key function is MUCH more efficient than a cmp function.
> Comparison functions end up doing much more work, and hence are very much
> slower, than a key function.
>
> Also note that in recent versions of Python, you can do without the lambda
> function and use the special "itemgetter" function:
>
>
> py> from operator import itemgetter
> py> L = [[1,2], [4,0], [3,2], [2,2], [5,1], [1,1]]
> py> L.sort(key=itemgetter(0), reverse=True)
> py> L.sort(key=itemgetter(1))
> py> print L
> [[4, 0], [5, 1], [1, 1], [3, 2], [2, 2], [1, 2]]
>
>
I tried this a lot yesterday but seemed to get a wrong answer but now I
realize its because of a bad test case. Thank you.


>
> Last but not least, I will show how to do it using a custom cmp function.
> But I recommend that you don't use this!
>
> def my_cmp(list1, list2):
>x = cmp(list1[1], list2[1])
>if x == 0:  # a tie
>x = cmp(list2[0], list1[0])  # swap the order for reverse sort
># or if you prefer, x = -cmp(list1[0], list2[0])
>return x
>
> sorted(L, my_cmp)
>
>
>
>
> --
> Steven
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Sarma Tangirala
On 7 February 2012 13:49, Alan Gauld  wrote:

> On 07/02/12 01:01, Nate Lastname wrote:
>
>> Exponents ... are **(or ^)
>>
>
> Not quite the ^ operator is a bitwise XOR...
>
> >>> 2^2
> 0
> >>> 2^1
> 3
>
> pow() is the other way to do exponents.
>
>
Is is better to use pow() against **?


> --
> Alan G
> 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<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Sarma Tangirala
On 8 February 2012 00:01, Steven D'Aprano  wrote:

> Sarma Tangirala wrote:
>
>  Is is better to use pow() against **?
>>
>
>
> Advantages of **
>
> - it is shorter to type x**y vs pow(x, y)
> - being an operator, it is slightly faster than calling a function
> - you can't monkey-patch it
>
> Disadvantages of **
>
> - being an operator, you can't directly use it as a function-object
> - it can't take three arguments
> - hard to google for "**"
> - you can't monkey-patch it
>
> Advantages of pow()
>
> - it is a function, so you can pass it around as an object
> - three argument form
> - easy to call help(pow) to see documentation
> - easy to google for "pow"
> - can be monkey-patched
>
> Disadvantages of pow()
>
> - a tiny bit slower due to the function call
> - slightly longer to type
> - can be monkey-patched
>
>
> Weigh up the advantages and disadvantages of each, and make the call which
> is better for you.
>
> (My preference is to use the ** operator.)
>
>
A simple "function call" argument would have done! :D Thanks for the survey!

Anyway, I was wondering about this, if internally pow() actually uses **. :P


>
>
> --
> Steven
>
> __**_____
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionaries

2012-02-10 Thread Sarma Tangirala
On 10 Feb 2012 19:45, "myles broomes"  wrote:
>
> Ive been given a challenge in the book im learning Python from and its
basically create a program with a dictionary of father - son pairs and
allow the user to add, replace and delete pairs. Ive done that without any
problems but ive been giving another challenge where I have to improve the
previous program by adding a choice that lets the user enter a name and get
back a grandfather. The program should still only use one dictionary of
father-son pairs and finally I have to make sure to include several
generations in your dictionary so that a match can be found. Im not sure I
fully understand the task because surely its only possible to have one key
and one value per pair but the challenge seems to want me to have a key
(for the father), a value (for the son) and then something else (for the
grandfather). Is this actually possible? Or am I just misinterpreting the
challenge?
>
>
> Myles Broomes
>

I don't think the task is asking you to modify the exisiting dictionary and
that its aim is to have you modify the way you search the dictionary.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Error Using A List And SMTP

2012-05-16 Thread Sarma Tangirala
Hey guys,

I was just trying out SMTP and I keep getting a attribute error,
*AttributeError:
'list' object has no attribute 'lstrip''*, when I use a list to store the
send address.

Code - http://pastebin.com/9NmCNdRb

Traceback - http://pastebin.com/m1cgKDnn

I'm not sure I understand why this is happening.

-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Using A List And SMTP

2012-05-16 Thread Sarma Tangirala
Hi Walter,


> All the headers in the MimeText object needs to be strings.  You can't
> directly pass a list object containing multiple recipients to the "To"
> header of your MimeText object on line 31 in your code, and expect it to
> work.  You've got to instead first convert the list to valid string and
> assign that instead, as that's what the MimeText object expects.  You can
> infer this from your error messages since lstrip() is a string method, and
> the code is (rightly) complaining that a list doesn't have an lstrip()
> method, which is understandable becuase you're getting the error when you
> pass a list as parameter.
>
>
Thank you for clearing that. Stupid mistake here. I forgot to change the
variable names.

But I do have another question. Maybe this is a misunderstanding about the
MimeText type, but why does MimeText care about the To field when the
actually sending is being done by SMTP?



-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Using A List And SMTP

2012-05-16 Thread Sarma Tangirala
On 16 May 2012 17:04, Sarma Tangirala  wrote:

> Hi Walter,
>
>
>> All the headers in the MimeText object needs to be strings.  You can't
>> directly pass a list object containing multiple recipients to the "To"
>> header of your MimeText object on line 31 in your code, and expect it to
>> work.  You've got to instead first convert the list to valid string and
>> assign that instead, as that's what the MimeText object expects.  You can
>> infer this from your error messages since lstrip() is a string method, and
>> the code is (rightly) complaining that a list doesn't have an lstrip()
>> method, which is understandable becuase you're getting the error when you
>> pass a list as parameter.
>>
>>
> Thank you for clearing that. Stupid mistake here. I forgot to change the
> variable names.
>
> But I do have another question. Maybe this is a misunderstanding about the
> MimeText type, but why does MimeText care about the To field when the
> actually sending is being done by SMTP?
>
>
OK. That was a stupid question. Sorry for the noise. Please ignore.


>
>
> --
> Sarma Tangirala,
> Class of 2012,
> Department of Information Science and Technology,
> College of Engineering Guindy - Anna University
>
>


-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Using A List And SMTP

2012-05-16 Thread Sarma Tangirala
On 16 May 2012 20:37, Alan Gauld  wrote:

> On 16/05/12 12:37, Sarma Tangirala wrote:
>
>>But I do have another question. Maybe this is a misunderstanding
>>about the MimeText type, but why does MimeText care about the To
>>field when the actually sending is being done by SMTP?
>>
>
>  OK. That was a stupid question. Sorry for the noise. Please ignore.
>>
>
> Actually for a beginners list I thought it was a perfectly reasonable
> question! :-)
>
> But I assume you figured out the answer for yourself so that's fine.
>
>
Not exactly. I did not read the immediate reply properly and got stupid. :P


>  --
> Alan G
> 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<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
An monkey typed up this email. Please excuse him if he made a stupid error!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing data from a set of files iteratively

2012-05-18 Thread Sarma Tangirala
On 18 May 2012 23:53, Spyros Charonis  wrote:

> Dear Python community,
>
> I have a set of ~500 files which I would like to run a script on. My
> script extracts certain information and
> generates several lists with items I need. For one of these lists, I need
> to combine the information from all
> 500 files into one super-list. Is there a way in which I can iteratively
> execute my script over all 500 files
> and get them to write the list I need into a new file? Many thanks in
> advance for your time.
>
> Spyros
>


Hi Spyros,

Did you try writing some code to achieve this?



-- 
An monkey typed up this email. Please excuse him if he made a stupid error!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] removing sq. of items.

2012-05-23 Thread Sarma Tangirala
On 23 May 2012 15:21, Bala subramanian  wrote:

> Friends,
> While iterating through each list item and printing/writing it, why does
> the sq. brackets get printed/written to the file. Just a small eg.code is
> given below.
>
> >>>N=100
> >>> myl=range(1,100+1)
> >>> new=[myl[i:i+15] for i in range(0, len(myl),15)]
> >>> for x in new: print x
>
>
When you slice 'myl[i:i+15]' you are creating a new list and adding that to
'new'. So essentially you are nesting new lists within a list comprehension.

Hope that helps!


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


-- 
An monkey typed up this email. Please excuse him if he made a stupid error!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Original indices after Sorting

2012-07-23 Thread Sarma Tangirala
On 24 July 2012 01:25, Ali Torkamani  wrote:

> Hi every one,
> How can we get the indices of values in the original list after sorting a
> list?
>
> for example:
>
> (Pdb) A=[ 1, -1, 0, 7, 9, 1.3, 2.9 ]
> (Pdb) A.sort()
> (Pdb) A
> [-1, 0, 1, 1.3, 2.9, 7, 9]
> (Pdb)
>
>
> Now I want to have the original indices of the sorted list, i.e:
>
> [1, 2, 0, 5, 6, 3, 4]
>
>
>
This should be of help ...
http://stackoverflow.com/questions/7851077/how-to-return-index-of-a-sorted-list...
 it uses the sorted method to sort a list rather than A.sort()


-- 
An monkey typed up this email. Please excuse him if he made a stupid error!
  .
.
. . .
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Trying to get next item from a list

2012-09-17 Thread Sarma Tangirala
On 17 September 2012 12:04, Santosh Kumar  wrote:

> Here is the script:
>
> alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
> 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
> 'z']
> i = input("Press any English alphabet: ")
> current = alphabets.index(i)
> print(current)
> next = current+1
> print(next)
> print(alphabets.index(next))
>
> I am getting a ValueError.
>
> And as you can see, I just trying to get the next item. So is there
> any way I can get same functionality in less line of codes?
>
> 
When you access index the second time you are trying to do so with the
value of the index.

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


[Tutor] Quick Question on String Compare

2013-05-31 Thread Sarma Tangirala
Hi,

I had a quick question on how string compare works. If did '1001' <= '999'
I get true. I know how the string compare works but I was wondering why it
were so. Why doesn't the string length factor into the comparison? For
example, If I compared character-by-character but also found how different
the lengths are, I could avoid a wrong logical answer as in the example
above. Any thoughts?

Thanks

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