Re: [Tutor] Efficiency

2011-06-25 Thread Alexandre Conrad
2011/6/25 naheed arafat : > 1) zip('How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) > [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] map(lambda i,j:(i,j),'How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) > [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] > > Which on

Re: [Tutor] Class methods

2011-06-22 Thread Alexandre Conrad
David, 2011/6/22 David Merrick : >     # listen to your critter >     elif choice == "1": >     for critter in farmlet: >     farmlet.talk() You want to call .talk() on your "critter" instance which has the .talk() method, not on farmlet (which is a list as the error m

Re: [Tutor] nitinchandra rubbish on list

2011-06-19 Thread Alexandre Conrad
2011/6/19 Alexandre Conrad : > 2011/6/19 Steven D'Aprano : >> I've been sending many lists to this list, and haven't received any such >> autoreplies. I suspect that you are getting them because you are replying >> directly to the sender, and CC'ing the lis

Re: [Tutor] nitinchandra rubbish on list

2011-06-19 Thread Alexandre Conrad
2011/6/19 Steven D'Aprano : > I've been sending many lists to this list, and haven't received any such > autoreplies. I suspect that you are getting them because you are replying > directly to the sender, and CC'ing the list. > > Stop replying to the sender, and the problem will probably go away.

Re: [Tutor] No module named player_data

2011-06-05 Thread Alexandre Conrad
2011/6/5 Michael bridges : > one of the things i deleted was __init__.py & __init__.pyc [thought it was > not used, then read import again and put it back. still not working] You always need an __init__.py file in a folder that you want to import in Python. That tells Python to consider the folde

Re: [Tutor] No module named player_data

2011-06-05 Thread Alexandre Conrad
2011/6/5 Michael bridges : > why does this happen? > > server [folder] >       player_data [folder] >       server.py > > Traceback (most recent call last): >  File > "C:\Users\MySelf\Program\game_stuff\Game_28_02_11\Servers\server_client_begining\server.py", > line 3, in >    from player_data i

Re: [Tutor] python "glue"

2011-06-05 Thread Alexandre Conrad
I think by "glue language", it meant that it's also a "lightweight" programming language in a sense that it can be used for scripting. Just slap pieces of code and external programs together and make it all work in harmony. When I hear "gluing", I think you did not write everything from scratch but

Re: [Tutor] Loop

2011-06-04 Thread Alexandre Conrad
Vincent, You will need to move the line that flips the coin: coin = random.randint(1,2) and the if/else logic *inside* the loop so it will be repeated as many times as needed. I'm not sure what you want to do with the input() inside the loop. Remove this. Alex 2011/6/4 Vincent Balmori : > H

Re: [Tutor] Structured files?

2011-06-02 Thread Alexandre Conrad
2011/6/2 Válas Péter : > I can create files and write strings/unicodes. > Is it possible to write a list, a dictionary or an object or anything into a > file? Or do I have to transform them to strings? As suggested by Walter, you should use the Pickle module to serialize your Python objects so the

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
2011/6/1 Marilyn Davis : > Maybe I'm getting what you say, Alexandre and Ramit. > > When you import logging, it imports string, but it won't if you have a > string of your own already imported. > > So, when logging depends on string, it'll get mine and crash. > > But __init__.py helps what in this

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
attribute 'lower' When "logging" is being imported, internally it also imports standard Python "string" module, which is *already* in sys.modules (your own). So imagine if Python also imported any directory without a __init__.py file, system wide, you might have rand

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
2011/5/31 Marilyn Davis : > I don't really understand why __init__.py is necessary -- except that it > makes the packaging scheme work. > > The Python Manual by Guido van Rossum and Fred L. Drake says: > > ... this is done to prevent directories with a common name, such as > string, from unintentio

Re: [Tutor] Strategy to read a redirecting html page

2011-05-31 Thread Alexandre Conrad
Hi Karim, When you hit the page and you get an HTTP redirect code back (say, 302), you will need to make another call to the URL specified in the "Location" parameter in the response headers. Then you retrieve that new page and you can check you got an acceptable HTTP response code (such as 200) a

Re: [Tutor] Making a simple web server in Python

2011-05-30 Thread Alexandre Conrad
2011/5/30 Michael bridges : >  File > "C:\Users\MySelf\Program\game_stuff\Python_Server_code_and_test\pythonweb\webserver.py", > line 56, in main >    server = HTTPServer(('', 80), MyHandler) >  File "C:\Python31\lib\socketserver.py", line 400, in __init__ >    self.server_bind() >  File "C:\Pyth

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alexandre Conrad
2011/5/30 Marilyn Davis : > If we are coding via a vote, I'd be with Alan. > > If Timo adds non-parser modules, and they get through his glob filter, > then surely his code will break with a nice error statement and that would > remind him of his convention. Sure. From my point of view, I prefer a

Re: [Tutor] Finding error from os.system(cmd)

2011-05-30 Thread Alexandre Conrad
Hi Kann, I haven't looked at your problem closely but you might need to explicitly tell Python where to output stderr/stdout. I just ran os.system('ls -al') on my Linux box and it seems to print both stderr/stdout to my terminal. The return value is the return code of the process (might be differe

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alexandre Conrad
2011/5/30 Alexandre Conrad : > selected_parser = "parser1" > parser = parsers[selected_parser] > parser = Parser() > ... I meant to have a capital P on the second line of course: selected_parser = "parser1" Parser = parsers[selected_parser] parser = Parser(

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alexandre Conrad
2011/5/30 Alan Gauld : > But this means having to maintain the list in init.py. > Why not use the os functions to read the file names > dynamically and build the list that way? Provided > the files use a standard naming scheme you don't > need to change the init code. I wouldn't do that. If Timo a

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alexandre Conrad
2011/5/30 Timo : > When the user clicks a button, I want to show all available parsers and use > the choosen one when the user clicks "ok". > Is it ok to place the following code in the __init__.py? > from parser1 import Parser1 > from parser2 import Parser2 > def get_parsers(): >    return [Parser

Re: [Tutor] unicode help

2011-05-28 Thread Alexandre Conrad
     value = self.__class__.symbol +  float.__str__(self) >        return value > > class Yen(Currency): >    symbol = unichr(165) > > def main(): >    y = Yen(100) >    print unicode(y) > > main() > > """ > ¥100.0 > """ > >

Re: [Tutor] unicode help

2011-05-28 Thread Alexandre Conrad
When Python loads your file from your file system, it assumes all characters in the file are ASCII. But when it hits non-ASCII characters (currency symbols), Python doesn't know how to interpret it. So you can give Python a hint by putting at the top of your file the encoding of your file: After t