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
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,
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
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
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
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
ppreciated.
regards, Tor Erik
--
http://mail.python.org/mailman/listinfo/python-list
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
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'
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
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
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 ' + \
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
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
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
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
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
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
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
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
>
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
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
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
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
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.
&
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
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.
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
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
--
"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
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
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
Hi
How can I determine the type of a socket (TCP or UDP) object?
regards tores
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
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
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
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
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
43 matches
Mail list logo