Re: [Tutor] Output not legible when debugging with ipdb

2013-11-26 Thread eryksun
On Tue, Nov 26, 2013 at 7:17 PM, Walter Prins wrote: > Actually now that I write this -- I suddenly vaguely remembering installing > PyReadline back when I was setting up IPython in order to get colour and a > couple of other things working properly... so presumably it does the ANSI > interpretati

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Dominik George
> >for x in xrange(len(animal)): > >if animal[x].isdigit(): > >animal[x] = int(animal[x]) > > > > Before posting anything else would you please do a tutorial > yourself. The above for loop is appalling newbie code, I'll leave > you to post the Pythonic format. Can I trust

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Mark Lawrence
On 27/11/2013 00:57, Dominik George wrote: Hi, I have a list with mixed strings/integers. I want to convert this to a list of lists, and I want the numbers to get stored as integers. First, let's do it with a list comprehension. You should really learn those if you do serious Python program

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Alan Gauld
On 26/11/13 19:00, Sam Lalonde wrote: >>> list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] >>> list2 = [] >>> for animal in list1: ... animal = animal.split() ... list2.append(animal) ... This could be a list comprehension: list2 = [animal.split() for animal in list1] >>> print list

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Amit Saha
On Wed, Nov 27, 2013 at 5:00 AM, Sam Lalonde wrote: > Hi, I am very new to python. > > I have a list with mixed strings/integers. I want to convert this to a list > of lists, and I want the numbers to get stored as integers. > list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] list2 = []

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Dominik George
Hi, > I have a list with mixed strings/integers. I want to convert this to a > list of lists, and I want the numbers to get stored as integers. First, let's do it with a list comprehension. You should really learn those if you do serious Python programming ;)! list2 = [[int(z) if z.isdigit(

[Tutor] Splitting lists with strings and integers

2013-11-26 Thread Sam Lalonde
Hi, I am very new to python. I have a list with mixed strings/integers. I want to convert this to a list of lists, and I want the numbers to get stored as integers. >>> list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] >>> list2 = [] >>> for animal in list1: ... animal = animal.split() ... lis

Re: [Tutor] Output not legible when debugging with ipdb

2013-11-26 Thread Walter Prins
Hi, Thanks for the highly educational response. On 26 November 2013 23:24, eryksun wrote: > On Tue, Nov 26, 2013 at 4:28 PM, Walter Prins wrote: > > > > honest. Regarding Powershell (vs for example cmd.exe): The (slightly) > > perplexing/irritating/annoying thing is that the older cmd.exe she

Re: [Tutor] string replacement in Python 2 and 3

2013-11-26 Thread Steven D'Aprano
On Tue, Nov 26, 2013 at 11:42:29AM -0800, Albert-Jan Roskam wrote: > Hi, > > String replacement works quite differently with bytes objects in > Python 3 than with string objects in Python 2. What is the best way to > make example #1 below run in Python 2 and 3? If you are working with text str

Re: [Tutor] Output not legible when debugging with ipdb

2013-11-26 Thread eryksun
On Tue, Nov 26, 2013 at 4:28 PM, Walter Prins wrote: > > honest. Regarding Powershell (vs for example cmd.exe): The (slightly) > perplexing/irritating/annoying thing is that the older cmd.exe shell, which > uses a standard old-school NT console window, does support ANSI escape > sequences (but is

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Steven D'Aprano
On Tue, Nov 26, 2013 at 04:57:56PM +, Alan Gauld wrote: > On 26/11/13 16:49, Peter Otten wrote: > > >>When executing the program, in case the user input is "for", "not", > >>"True", "while" Python interprets that as a command and changes the > >>input's color to the corresponding command. > ..

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Steven D'Aprano
On Tue, Nov 26, 2013 at 05:15:31PM +0100, Rafael Knuth wrote: > Hej there, > > simple issue I couldn't find a solution for: > > YourName = input(str("What is your name?")) > print("Hello", YourName) > > When executing the program, in case the user input is "for", "not", > "True", "while" Python

Re: [Tutor] Output not legible when debugging with ipdb

2013-11-26 Thread Walter Prins
Hi, On 26 November 2013 19:01, eryksun wrote: > On Tue, Nov 26, 2013 at 11:50 AM, Walter Prins wrote: > > All those arrows and codes you see are called "ANSI escape codes" or > "ANSI > > control codes". It's a way to control/signal text colour and formatting > > inline for text terminals. I d

Re: [Tutor] string codes

2013-11-26 Thread Danny Yoo
Hi Denis, For reference, you can explore the documentation to find out what strings can do: http://docs.python.org/3/library/stdtypes.html#text-sequence-type-str > What is the method to get a code or list of codes inside a string: > s = "abcde" > c = s.code(2) > ass

[Tutor] string replacement in Python 2 and 3

2013-11-26 Thread Albert-Jan Roskam
Hi, String replacement works quite differently with bytes objects in Python 3 than with string objects in Python 2. What is the best way to make example #1 below run in Python 2 and 3? Should one really decode the bytes keys and (if applicable) the values to unicode? The code gets so bloated wi

Re: [Tutor] Dict

2013-11-26 Thread Danny Yoo
> > Is it possible to sort dict & to get result as dict? > if it is possible, please give some example. > Just to understand the question more, can you give more details? Why would you want a sorted dict? That is, it is not directly obvious what your intent is yet, so you need to say more. Are

Re: [Tutor] Output not legible when debugging with ipdb

2013-11-26 Thread eryksun
On Tue, Nov 26, 2013 at 11:50 AM, Walter Prins wrote: > All those arrows and codes you see are called "ANSI escape codes" or "ANSI > control codes". It's a way to control/signal text colour and formatting > inline for text terminals. I don't know whether or not it does, but if > Windows Powershe

Re: [Tutor] string codes

2013-11-26 Thread eryksun
On Tue, Nov 26, 2013 at 6:34 AM, Steven D'Aprano wrote: > > I think that views would be useful for *very large strings*, but very > large probably means a lot larger than you might think. For small > strings, say under a few hundred or perhaps even thousand characters, > making a copy of the subst

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread eryksun
On Tue, Nov 26, 2013 at 6:13 AM, Dominik George wrote: > Now when zou instantiate the class, then the dictionary is copied to the > instance (carying references to the same data inside it, mind you!), Perhaps the above is just a simple mistake of wording, but to be clear, the class dict isn't cop

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Mark Lawrence
On 26/11/2013 10:00, Dominik George wrote: Hi Reuben, class Animal(): flag = True print flag Are you sure you know what this does ;)? Normally, you initialize all variables in the constructor. Wrong. You normally initialise names in the initialiser which is called __init__

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Peter Otten
Alan Gauld wrote: > On 26/11/13 16:49, Peter Otten wrote: > >>> When executing the program, in case the user input is "for", "not", >>> "True", "while" Python interprets that as a command and changes the >>> input's color to the corresponding command. > ... >> >> Are you running the program insid

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Rafael Knuth
> OK, That's what you'd expect in 3.3 because raw_input is now input(). > > But in that case input() should not do anything with your input. > > Can you post a session showing the input and the odd behaviour? YourName = input(str("What is your name ?")) print("Hello", YourName) Exemplary input &

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Alan Gauld
On 26/11/13 16:49, Peter Otten wrote: When executing the program, in case the user input is "for", "not", "True", "while" Python interprets that as a command and changes the input's color to the corresponding command. ... Are you running the program inside idle? The (in this case unwanted) sy

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread ALAN GAULD
Please always use ReplyAll to include the list. > thanks - that's weird. I am using Python 3.3.0 and changed input() to >raw_input() but I get an error message now: > >NameError: name 'raw_input' is not defined OK, That's what you'd expect in 3.3 because raw_input is now input(). But in that c

Re: [Tutor] Output not legible when debugging with ipdb

2013-11-26 Thread Walter Prins
Hi, On 26 November 2013 14:22, Peter Zorn wrote: > Hi everyone - > > I'm fairly new to Python and I'm working through this ( > http://quant-econ.net/) tutorial to learn the language. > > I've encountered a problem with the ipdb debugger and I > wonder if anyone can help. When I run this cod

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Peter Otten
Rafael Knuth wrote: > Hej there, > > simple issue I couldn't find a solution for: > > YourName = input(str("What is your name?")) > print("Hello", YourName) > > When executing the program, in case the user input is "for", "not", > "True", "while" Python interprets that as a command and changes

Re: [Tutor] Output not legible when debugging with ipdb

2013-11-26 Thread Alan Gauld
On 26/11/13 14:22, Peter Zorn wrote: I've encountered a problem with the ipdb debugger and I wonder if anyone can help. When I run this code ( http://quant-econ.net/ipython.html#setting-a-break-point) and include the "import ipdb; ipdb.set_trace()" command line, the ipdb debugger starts but its

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Alan Gauld
On 26/11/13 16:15, Rafael Knuth wrote: YourName = input(str("What is your name?")) print("Hello", YourName) When executing the program, in case the user input is "for", "not", "True", "while" Python interprets that as a command Sounds like you are using Python v2. You need to yuse raw_input()

[Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Rafael Knuth
Hej there, simple issue I couldn't find a solution for: YourName = input(str("What is your name?")) print("Hello", YourName) When executing the program, in case the user input is "for", "not", "True", "while" Python interprets that as a command and changes the input's color to the corresponding

Re: [Tutor] string codes

2013-11-26 Thread ALAN GAULD
Pleae use ReplyAll to include the list. > c = ord(s[2]) > >Yes, that's it: i forgot about Python's builtin functions, only searched among >methods. Then, two more questions: >-1- Why isn't this a str method? s.ord() [or better s.code()] looks natural, >doesn't it?Because it operates on a single

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Reuben
Yes! I got my answer now. Thanks all @Dominick: sorry about my explanation. On 26-Nov-2013 4:24 PM, "Alan Gauld" wrote: > On 26/11/13 07:30, Reuben wrote: > >> Hi, >> >> Following is my code: >> # >> class Animal(): >> >>flag = True >>p

Re: [Tutor] string codes

2013-11-26 Thread Alan Gauld
On 26/11/13 11:59, Steven D'Aprano wrote: test = s.startswith("bcd", 1, -1) That doesn't work, unfortunately: py> s = "abcdZZZ" py> s[1:-1] == "bcd" False py> s.startswith("bcd", 1, -1) True Oops. You'd have to do both startswith() and endswith() tests, and even then it doesn't work:

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Steven D'Aprano
On Tue, Nov 26, 2013 at 01:00:18PM +0530, Reuben wrote: > Hi, > > Following is my code: > # > class Animal(): > > flag = True > print flag This "flag" is a class attribute, which means it is shared by all instances. Every Animal will see t

Re: [Tutor] Dict

2013-11-26 Thread Steven D'Aprano
On Tue, Nov 26, 2013 at 04:37:28PM +0530, Sunil Tech wrote: > Hi Friends, > > Is it possible to sort dict & to get result as dict? > if it is possible, please give some example. No it is not possible, dicts are deliberately unsorted. Please read my explanation why from yesterday: https://mail.p

Re: [Tutor] string codes

2013-11-26 Thread Steven D'Aprano
On Tue, Nov 26, 2013 at 10:01:14AM +, Alan Gauld wrote: > >Is there a method to compare a substring, without building a substring > >from the big one? Like startswith or endswith, but anywhere inside the > >string? > > test = s[1, -1] == "bcd"# no!, builds a substring > > I assume you

Re: [Tutor] Dict

2013-11-26 Thread Dominik George
Hi, > Is it possible to sort dict & to get result as dict? > if it is possible, please give some example. By what do you want to sort it? By key? By value? By a combination of both? Cheers, Nik -- Ein Jabber-Account, sie alle zu finden; ins Dunkel zu treiben und ewig zu binden; im Nat

Re: [Tutor] string codes

2013-11-26 Thread Steven D'Aprano
On Tue, Nov 26, 2013 at 10:19:46AM +0100, spir wrote: > What is the method to get a code or list of codes inside a string: > s = "abcde" > c = s.code(2) > assert(c == 0x63) > ? Use indexing to get the character you want, then ord() to return its ordinal value. ord(s[2]) > ===

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Dominik George
Hi, > By setting test.flag you are creating a new instance level attribute > that exists only within the test instance. That's legal Python > but usually its not a good idea to have different instances of > the same class having different attributes. maybe this becomes clearer by breaking down th

[Tutor] Dict

2013-11-26 Thread Sunil Tech
Hi Friends, Is it possible to sort dict & to get result as dict? if it is possible, please give some example. Thank you in advance. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/li

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Alan Gauld
On 26/11/13 07:30, Reuben wrote: Hi, Following is my code: # class Animal(): flag = True print flag def __init__(self,name): self.name = name print self.name def walk(self

Re: [Tutor] string codes

2013-11-26 Thread Alan Gauld
On 26/11/13 09:19, spir wrote: What is the method to get a code or list of codes inside a string: s = "abcde" c = s.code(2) assert(c == 0x63) If I understand what you want then I think its the ord() function you are looking for c = ord(s[2]) === sub compare === Is there a m

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Dominik George
Hi Reuben, > class Animal(): > > flag = True > print flag Are you sure you know what this does ;)? Normally, you initialize all variables in the constructor. > test.flag = False > 1)Inside the Animal class(), How can I set the variable 'flag' to FALSE? Your qustion is a bit u

[Tutor] How to set variables inside a class()

2013-11-26 Thread Reuben
Hi, Following is my code: # class Animal(): flag = True print flag def __init__(self,name): self.name = name print self.name def walk(self): print "I am walking" if __name__ == '__main__':

[Tutor] string codes

2013-11-26 Thread spir
Hello, I am coming back to Python after quite a long time, have forgotten everything, and don't know anything of python 3. I use python 3.3 for its nice unicode text type. === codes === What is the method to get a code or list of codes inside a string: s = "abcde" c = s.code(