Re: "do" as a keyword

2007-12-11 Thread Tor Erik Sønvisen
5) >>> b = range(5, 8) >>> min(a) if sum(a) < sum(b) else min(b) 0 In prior versions, you can use the and/or trick: >>> (sum(a) < sum(b) and [min(a)] or [min(b)])[0] 0 -Tor Erik -- http://mail.python.org/mailman/listinfo/python-list

Simple eval

2007-11-18 Thread Tor Erik Sønvisen
eral, etc are appreciated. As this is a contribution to the community I suggest that any improvements are posted in this thread... -Tor Erik Code (tested on 2.5, but should work for versions >= 2.3): ''' Recursive evaluation of: tuples, lists, dicts, strings, unicode strings,

Convert obejct string repr to actual object

2007-10-08 Thread Tor Erik Sønvisen
t the source sending the object I'm sure someone must have had the same need and created code for it... Maybe Pypy has what I need??? Haven't looked though... Regards, Tor Erik PS: The string repr is created by a server outside of my control... -- http://mail.python.org/mailman/listinfo/python-list

Tapping into the access of an int instance

2007-09-20 Thread Tor Erik Sønvisen
def __init__(self, *a, **k): super(Int, self).__init__(self, *a, **k) >>> i = Int(1) >>> i 1 Regards, Tor Erik -- http://mail.python.org/mailman/listinfo/python-list

Re: Just bought Python in a Nutshell

2007-09-15 Thread Tor Erik Sønvisen
etter programmer, not just a better Python programmer. I only wish I'd read through it earlier, which would have saved me a lot of agony:) -Tor Erik -- http://mail.python.org/mailman/listinfo/python-list

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

python shelve on win vs unix

2007-02-09 Thread Tor Erik Soenvisen
ppreciated. regards, Tor Erik -- http://mail.python.org/mailman/listinfo/python-list

str and __setitem__

2007-01-25 Thread Tor Erik Soenvisen
Hi, What do I need to do to make the code below work as expected: class str2(str): def __setitem__(self, i, y): assert type(y) is str assert type(i) is int assert i < len(self) self = self[:i] + y + self[1+i:] a = str2('1

Re: len(var) is [CONSTANT] equal to len(var) == [CONSTANT]?

2006-11-23 Thread Tor Erik Soenvisen
Steven D'Aprano <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > On Thu, 23 Nov 2006 10:48:32 +, Tor Erik Soenvisen wrote: > >> Hi, >> >> >> (len(['']) is 1) == (len(['']) == 1) => True > > You shouldn'

len(var) is [CONSTANT] equal to len(var) == [CONSTANT]?

2006-11-23 Thread Tor Erik Soenvisen
d, id=%d' % (i, j, id (i)) which executes fine. Hence, 0- is okey... But this is a relatively small range, and sooner or later you probably get two numbers with the same id... Thoughts anyone? Regards Tor Erik PS: For those of you who don't know: keyword is compares object identities

Code feedback

2006-11-17 Thread Tor Erik Soenvisen
ester. Here is the server code, HTTPServer.py: # Basic, threaded HTTP server, serving requests via python scripts # Author: Tor Erik Soenvisen # Std lib imports import BaseHTTPServer, os, threading, Queue class HTTPServer(BaseHTTPServer.HTTPServer): """ A threaded HTTP serve

Protecting against SQL injection

2006-10-24 Thread Tor Erik Soenvisen
Hi, How safe is the following code against SQL injection: # Get user privilege digest = sha.new(pw).hexdigest() # Protect against SQL injection by escaping quotes uname = uname.replace("'", "''") sql = 'SELECT privilege FROM staff WHERE ' + \

FTP over SSL

2006-10-20 Thread Tor Erik Soenvisen
Hi, Anyone know about existing code supporting FTP over SSL? I guess pycurl http://pycurl.sourceforge.net/ could be used, but that requires knowledge of libcurl, which I haven't. regards -- http://mail.python.org/mailman/listinfo/python-list

Assigning different Exception message

2006-10-12 Thread Tor Erik Soenvisen
try: self.cursor.execute(sql) except AttributeError, e: if e.message == "oracleDB instance has no attribute 'cursor'": e.message = 'oracleDB.open() must be called before' + \ ' oracleDB.query()' raise At

Oracle database export

2006-10-05 Thread Tor Erik Soenvisen
Hi, I need to export an Oracle database to a DDL-formated file. On the Web, I found a Python script that did exactly this for a MS Access database, but not one for Oracle databases. Does anyone know of such a tool or Python script. regards tores -- http://mail.python.org/mailman/listinfo/pytho

Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Tor Erik
Jean-Paul Calderone wrote: > On Thu, 14 Sep 2006 11:13:59 +0200, Tor Erik <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I've developed an application were I've used Tkinter for the GUI. >> When I ran the GUI in another thread than the main, it kept locking &g

Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Tor Erik
Bjoern Schliessmann wrote: > Tor Erik wrote: > >> But could anyone tell me why running these in a thread other than >> the main one doesn't work? > > Just for personal interest: Why would you want to run the GUI in > another thread? It's common to leave

Why not event-driven packages in other than the main thread?

2006-09-14 Thread Tor Erik
Hi, I've developed an application were I've used Tkinter for the GUI. When I ran the GUI in another thread than the main, it kept locking up. I experienced similar problems with Twisted. Both of these tools are event-based, so I guess that is the root of the problem... But could anyone tell me

Re: Windows bandwidth monitor

2006-09-13 Thread Tor Erik
RunLevelZero wrote: > Hey guys, I've done some searching but can't seem to find anything that > helps me out. I want to write a simple bandwidth monitor that will sit > in the taskbar of windows and tell me my upload and download speeds. I > intend to use wxpython for the little taskbar icon. If an

Re: What algorithm does Python use to evaluate: if substring in string

2006-09-09 Thread Tor Erik
Alex Martelli wrote: > Tor Erik <[EMAIL PROTECTED]> wrote: > >> I would be surprised if it is the naive: > > Yep -- it's "a mix between Boyer-Moore and Horspool with a few more > bells and whistles on the top", as documented and implemented in >

What algorithm does Python use to evaluate: if substring in string

2006-09-09 Thread Tor Erik
I would be surprised if it is the naive: m = 0 s1 = "me" s2 = "locate me" s1len = len(s1) s2len = len(s2) found = False while m + s1len <= s2len: if s1 == s2len[m:m+s1len]: found = True break m += 1 -- http://mail.python.org/mailman/listinfo/python

Get CPU usage of a single process in Windows

2006-09-08 Thread Tor Erik
Hi, This should be possible as Taskmanager tracks CPU usage for every process... Anyone know how this can be done? regards -- http://mail.python.org/mailman/listinfo/python-list

Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Tor Erik
Tor Erik wrote: > Fredrik Lundh wrote: >> Tor Erik wrote: >> >>> The reason is that my application does about 16 connects and data >>> transfers per second, to the same 16 remote hosts. After approx 200 >>> secs there are 4000 sockets waiting to be ga

Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Tor Erik
Fredrik Lundh wrote: > Tor Erik wrote: > >> The reason is that my application does about 16 connects and data >> transfers per second, to the same 16 remote hosts. After approx 200 >> secs there are 4000 sockets waiting to be garbage collected by the OS. > > what

Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Tor Erik
Sybren Stuvel wrote: > Tor Erik enlightened us with: >> The reason is that my application does about 16 connects and data >> transfers per second, to the same 16 remote hosts. After approx 200 >> secs there are 4000 sockets waiting to be garbage collected by the >> OS. &

Client-side TCP socket receiving "Address already in use" upon connect

2006-09-02 Thread Tor Erik
Hi, The reason is that my application does about 16 connects and data transfers per second, to the same 16 remote hosts. After approx 200 secs there are 4000 sockets waiting to be garbage collected by the OS. At this point is seems that connect loops and starts using the same local addresses i

running windows 'start' cmd using spawnl

2006-08-23 Thread Tor Erik
Hi, I need to start a program in a new cmd-window. To do this I need to execute: start [command] With os.system this is straight-forward. But I need to do it with spawnl and P_NOWAIT. I.e, asynchronously. The problem is that I need to know the path where start resides, which I'm unable to find.

Most efficient way of storing 1024*1024 bits

2005-11-02 Thread Tor Erik S�nvisen
Hi I need a time and space efficient way of storing up to 6 million bits. Time efficency is more important then space efficency as I'm going to do searches through the bit-set. regards tores -- http://mail.python.org/mailman/listinfo/python-list

output events on select

2005-09-30 Thread Tor Erik S�nvisen
Hi When using select, what exactly will trigger an output-event? I have a socket registered in the output-list of the select but an output-event is never generated for that socket. I know the socket is ready to send data, so how can I make select return with an output-event? regards tores --

Re: Where to find python c-sources

2005-09-30 Thread Tor Erik S�nvisen
"Erik Max Francis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Tor Erik Sønvisen wrote: > >> I need to browse the socket-module source-code. I believe it's contained >> in the file socketmodule.c, but I can't locate this file... Whe

Where to find python c-sources

2005-09-29 Thread Tor Erik S�nvisen
Hi I need to browse the socket-module source-code. I believe it's contained in the file socketmodule.c, but I can't locate this file... Where should I look? regards tores -- http://mail.python.org/mailman/listinfo/python-list

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

Determine type of a socket

2005-09-26 Thread Tor Erik S�nvisen
Hi How can I determine the type of a socket (TCP or UDP) object? regards tores -- http://mail.python.org/mailman/listinfo/python-list

Re: Bluetooth

2005-09-23 Thread Tor Erik S�nvisen
ing??? regards tores "Paul Boddie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Tor Erik Sønvisen wrote: > I'm making a server-side solution in Python and need to be able to > communicate through bluetooth. Is there any bluetooth-packages out there > f

Bluetooth

2005-09-23 Thread Tor Erik S�nvisen
Hi I'm making a server-side solution in Python and need to be able to communicate through bluetooth. Is there any bluetooth-packages out there for python? regards tores -- http://mail.python.org/mailman/listinfo/python-list

Convert from unicode to int

2005-09-22 Thread Tor Erik S�nvisen
Hi Is there any simpler way to convert a unicode numeric to an int than: int(u'1024'.encode('ascii')) ?? 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