Re: "do" as a keyword

2007-12-11 Thread Tor Erik Sønvisen
> I also started to ponder about the "'do > something' if 'true' else 'do this'", and pondered if perhaps > this statement could do with the including of the keyword do. Python has support for this in versions >= 2.5: >>> a = range(0, 5) >>> b = range(5, 8) >>> min(a) if sum(a) < sum(b) else min(

Simple eval

2007-11-18 Thread Tor Erik Sønvisen
Hi, A while ago I asked a question on the list about a simple eval function, capable of eval'ing simple python constructs (tuples, dicts, lists, strings, numbers etc) in a secure manner: http://groups.google.com/group/comp.lang.python/browse_thread/thread/58a01273441d445f/ >From the answers I got

Convert obejct string repr to actual object

2007-10-08 Thread Tor Erik Sønvisen
Hi, I've tried locating some code that can recreate an object from it's string representation... The object in question is really a dictionary containing other dictionaries, lists, unicode strings, floats, ints, None, and booleans. I don't want to use eval, since I can't trust the source sending

Tapping into the access of an int instance

2007-09-20 Thread Tor Erik Sønvisen
Hi, Does anyone know how to interrupt the lookup of an integer value? I know I need to subclass int, since builtin types can't be altered directly... Below is how far I've come... What I want is to tap into the access of instance i's value 1... >>> class Int(int): def __init__(self, *a,

Re: Just bought Python in a Nutshell

2007-09-15 Thread Tor Erik Sønvisen
Python in a nutshell also comes in a second edition: http://www.oreilly.com/catalog/pythonian2/index.html. Here, many of the new features in Python 2.5 are included. I haven't read through the first the edition, but I can honestly say that reading through the second edition has made me a better pro

The reverse of encode('...', 'backslashreplace')

2007-09-03 Thread Tor Erik Sønvisen
Hi, How can I transform b so that the assertion holds? I.e., how can I reverse the backslash-replaced encoding, while retaining the str-type? >>> a = u'æ' >>> b = a.encode('ascii', 'backslashreplace') >>> b '\\xe6' >>> assert isinstance(b, str) and b == 'æ' Traceback (most recent call last): F

How can I set the size of a window with tkinter?

2005-09-27 Thread Tor Erik Sønvisen
Hi I create a canvas that is to big for the default window-size, so it gets cut to fit... How can I increase the window-size to make sure the canvas fits? regards tores -- http://mail.python.org/mailman/listinfo/python-list

using variable-value

2005-09-21 Thread Tor Erik Sønvisen
Hi In php I can assign a value to a variable and use this varaible to access a property in some object: $var = 'property'; $object->{$var} This will transelate to $object->property... Is this possible in Python? # Prints help on methods in Canvas-instance for method in dir(self.canvas): pr

Socket options

2005-09-12 Thread Tor Erik Sønvisen
Hi For an online game I'm developing I need some advice concerning tcp-sockets, and especially which socket options to set and not. What I want is a connection where nothing is buffered (but are sent immediatly), and I also want to keep the connections persistent until explicitly closed. The se

logging to two files

2005-04-20 Thread Tor Erik Sønvisen
Hi Have the following code: import logging logging.basicConfig(level = logging.DEBUG, format = '[%(levelname)-8s %(asctime)s] %(message)s', filename = 'rfs.log', filemode = 'w') When using logging.(debug

EOF-file missing

2005-04-14 Thread Tor Erik Sønvisen
Hi >From a client I read a file into a string using read(). On the server-side (it's a HTTPServer) i access the same string through the input stream rfile. However all useful read-methods (readlines, readline, read) expect an EOF before terminating. And for some reason the stream doesn't have th

select random entry from dictionary

2005-03-07 Thread Tor Erik Sønvisen
Hi How can I select a random entry from a dictionary, regardless of its key-values? regards tores -- http://mail.python.org/mailman/listinfo/python-list

Delete first line from file

2005-03-01 Thread Tor Erik Sønvisen
Hi How can I read the first line of a file and then delete this line, so that line 2 is line 1 on next read? regards -- http://mail.python.org/mailman/listinfo/python-list

kill a process in XP

2005-02-23 Thread Tor Erik Sønvisen
Hi. >From my Python-program I spawn a new process. When using P_NOWAIT spawnl returns the pid but in windows it returns a process handle. Later I want to kill this process. How can I do this when I only have the process handle? -tores- -- http://mail.python.org/mailman/listinfo/python-list