Re: Ordered dict by default

2009-02-05 Thread Bryan Olson
MRAB wrote: Paul Rubin wrote: bearophileh...@lycos.com writes: Now Ruby dicts are ordered by default: http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like ordered means the dict records come out in the same order you

Re: Ordered dict by default

2009-02-05 Thread Bryan Olson
Stephen Hansen wrote: Ooh, as an addendum... I found one case where I want insertion-and-update order: meaning that its an ordered dictionary that maintains insertion order, but an update to a particular item moves that item to the back so an update behaves like del d[key]; d[key] = value in

Re: Doc for extended call syntax; was: Re: unzip array of arrays?

2009-01-27 Thread Bryan Olson
Mark Wooding wrote: Steve Holden writes: No, you aren't mistaken. Looking at the * symbol in the 2.6 documentation index it lists only two references. The first is the language manual's explanation of its use in the def statement, the second is a transitory reference to its use in function

Re: Why GIL? (was Re: what's the point of rpython?)

2009-01-27 Thread Bryan Olson
Paul Rubin wrote: Bryan Olson fakeaddr...@nowhere.org writes: An object's __dict__ slot is *not* mutable; thus we could gain some efficiency by protecting the object and its dict with the same lock. I do not see a major win in Mr. Banks' point that we do not need to lock the object, just its

Re: Securing a database

2009-01-25 Thread Bryan Olson
kt83...@gmail.com wrote: Thank you very much Bryan. It does look like this is out of my league. As Peter Pearson noted, It is out of *everyone's* league. And Peter used to work for Cryptography Research, a small company that scored as high in this league as anyone. Maybe you can advance the

Doc for extended call syntax; was: Re: unzip array of arrays?

2009-01-24 Thread Bryan Olson
Tobiah wrote: Where can I read about this mysterious use of the '*'? Hmmm... that's a harder question than I thought. Am I missing it, or does Python's doc need a write-up of the extended call syntax? It only works in the context of the zip() function. It's hard to understand how the

Re: Securing a database

2009-01-23 Thread Bryan Olson
kt83...@gmail.com wrote: Anyways, if we can make it real hard for them to analyze also, I think we are in the good - esp since the clients are not extremely rich enough to go for professional analyzers -- Sounds like you have the digital rights management (DRM) problem. As Diez pointed out,

Re: Why GIL? (was Re: what's the point of rpython?)

2009-01-23 Thread Bryan Olson
Carl Banks wrote: [...] BTW, class instances are usually immutable and thus don't require a mutex in the system I described. Then you are describing a language radically different from Python. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list

Re: Why GIL? (was Re: what's the point of rpython?)

2009-01-23 Thread Bryan Olson
Paul Rubin wrote: Bryan Olson writes: BTW, class instances are usually immutable and thus don't require a mutex in the system I described. Then you are describing a language radically different from Python. That one threw me for a minute too, but I think the idea is that the class instance

Re: Why GIL? (was Re: what's the point of rpython?)

2009-01-23 Thread Bryan Olson
Carl Banks wrote: Paul Rubin wrote: Bryan Olson writes: BTW, class instances are usually immutable and thus don't require a mutex in the system I described. Then you are describing a language radically different from Python. That one threw me for a minute too, but I think the idea

Re: Why GIL? (was Re: what's the point of rpython?)

2009-01-23 Thread Bryan Olson
Carl Banks wrote: Bryan Olson wrote: Paul Rubin wrote: Bryan Olson writes: BTW, class instances are usually immutable and thus don't require a mutex in the system I described. Then you are describing a language radically different from Python. That one threw me for a minute too, but I

Re: Start Python at client side from web app

2009-01-21 Thread Bryan Olson
Thomas Guettler wrote: Sorry, I described my problem not well. Here is more information: Actually you did pretty well. [...] The main application is the intranet web application used with IE (ms windows client). Your idea of a custom mime-type, with a browser extension, should work. I

Re: socket send help

2009-01-07 Thread Bryan Olson
Gabriel Genellina wrote: James Mills escribió: Bryan Olson wrote: I thought a firewall would block an attempt to bind to any routeable address, but not to localhost. So using INADDR_ANY would be rejected. No. My understanding is that firewalls block network traffic, not system calls

Re: socket.error 24: too many open files

2009-01-07 Thread Bryan Olson
TheDavidFactor wrote: [...] It's a deamon that runs on a linux box and every 15 seconds it checks a MySQL table for new records, if there are any it creates a .call file on the Asterisk server using ssh, it also checks the Asterisk server, again via ssh, for any finished calls and if there are

Re: socket send help

2009-01-05 Thread Bryan Olson
Gabriel Genellina wrote: Bryan Olson escribió: Gabriel Genellina wrote: greyw...@gmail.com escribió: [...] A simple server: from socket import * myHost = '' Try with myHost = '127.0.0.1' instead - a firewall might be blocking your server. Just a nit: I'd say the reason to use

Re: Testing if an index is in a slice

2009-01-04 Thread Bryan Olson
Steven D'Aprano wrote: Here's a less verbose version which passes your test cases: def inslice(index, slc, len): Return True if index would be part of slice slc of a sequence of length len, otherwise return False. start, stop, stride = slc.indices(len) if stride 0:

Re: select.select and socket.setblocking

2009-01-03 Thread Bryan Olson
Laszlo Nagy wrote: [...] I have read the socket programming howto ( http://docs.python.org/howto/sockets.html#sockets ) but it does not explain how a blocking socket + select is different from a non blocking socket + select. Is there any difference? There is, but it may not effect you. There

Re: Testing if an index is in a slice

2009-01-03 Thread Bryan Olson
ajaksu wrote: On Jan 1, 4:12 pm, mma...@gmx.net wrote: I would like to check if an index is in a slice or not without iterating over the slice. Something like: isinslice(36, slice(None, 34, -1)) True I think it'd be feasible for slices that can be mapped to ranges[1], but slices are more

Re: socket send help

2009-01-03 Thread Bryan Olson
Gabriel Genellina wrote: greyw...@gmail.com escribió: [...] A simple server: from socket import * myHost = '' Try with myHost = '127.0.0.1' instead - a firewall might be blocking your server. Just a nit: I'd say the reason to use '127.0.0.1' instead of the empty string is that a

Re: Doubt on creating threads

2009-01-03 Thread Bryan Olson
koranth...@gmail.com wrote: I am creating an application and it creates ~1-2 threads every second and kill it within 10 seconds. After reading this I am worried. Is creating a thread a very costly operation? Compared to a procedure call it's expensive, but a couple threads per second is

Re: Very basic question

2008-12-23 Thread Bryan Olson
Sengly wrote: I can hack it by doing eval('1.0*12/5') but is there any better method? Where did you get the string? If you generated it, you might as well make one or both the operands float to begin with. If you got it as input, calling eval() on it is a world of security hurt. The right

Re: Twisted for non-networking applications

2008-12-22 Thread Bryan Olson
Kottiyath wrote: Is it a good idea to use Twisted inside my application, even though it has no networking part in it? Basically, my application needs lots of parallel processing - but I am rather averse to using threads - With or without threads, the Python interpreter does not do

Re: Event Driven programming - Doubts

2008-12-22 Thread Bryan Olson
Kottiyath wrote: [...] I have not yet understood the implementation of deferred. I went through a lot of tutorials, but I guess most places they expect that the user already understands how events are generated. The tutorials mention that there is no more threads once twisted is used. My

Re: socket and subprocess problem

2008-12-18 Thread Bryan Olson
James Mills wrote: subprocess process: #1. When my subprocess process has successfully started notify the parent. #2. When my subprocess process has successfully created a listening socket, notify the parent. parent process: #1. When our subprocess process has

Re: socket and subprocess problem

2008-12-15 Thread Bryan Olson
goat...@gmail.com wrote: In my python code I use subprocess.Popen to run and external program who will listen to a TCP port. And I also create a socket to connect to the TCP port that the external program is listening. I will get 'Connection refused, errno=111' when I try to socket.connect ().

Re: socket and subprocess problem

2008-12-15 Thread Bryan Olson
goat...@gmail.com wrote: Guys thanks to point it out. Yes, it's a race problem. I tried sleep long enough, then I can connect to the socket. I should add code to try to connect to the socket for a given time out. As Roy noted, that's the cheesy way. Are the kind of programmers who accept

Re: Thread Locking issue - Can't allocate lock (sem_init fail)

2008-12-15 Thread Bryan Olson
jams...@googlemail.com wrote: [...] The program is multithreaded to speed up the processing...there are input and output Queues. It's not the major point here, but are you aware of Python's GIL? Now, each domain entry is an class object containing various bits of info. Each domain class

Re: Bidirectional Networking

2008-12-14 Thread Bryan Olson
Emanuele D'Arrigo wrote: Bryan Olson wrote: Software firewalls will often simply refuse incoming connections. The basic protection of the garden-variety home router comes from network address translation (NAT), in which case TCP connections initiated from the inside will generally work

Re: Bidirectional Networking

2008-12-14 Thread Bryan Olson
Brian Allen Vanderburg II wrote: As for the backlog (5), this doesn't mean that you can only have a maximum of 5 established connections. Each established connection gets a new socket object. But what I think it means is that during the listen for an incoming connection on the listening

Re: Bidirectional Networking

2008-12-13 Thread Bryan Olson
Emanuele D'Arrigo wrote: Hey Bryan, thank you for your reply! Bryan Olson wrote: Is it possible then to establish both a server and a client in the same application? Possible, and not all that hard to program, but there's a gotcha. Firewalls, including home routers and software firewalls

Re: Bidirectional Networking

2008-12-12 Thread Bryan Olson
Emanuele D'Arrigo wrote: All the examples though are based on a client interrogating a server, with the client initiating the connection, obtaining something and then closing the connection. Basically the server is a reactive party: only if the client get in touch the server respond. Indeed,

Re: python an sqlite objects

2008-12-04 Thread Bryan Olson
Gerhard Häring wrote: Be sure to save it as BLOB, not TEXT. Suppose you have serialized your object as Python bytestring. serialized = ... ... .execute(insert into mytable(mycolumn) values (?), (sqlite3.Binary(serialized),)) This way you will get a BLOB in the form of a Python buffer

Off Topic: Re: Obama's Birth Certificate - Demand that US presidential electors investigate Obama's eligibility

2008-12-04 Thread Bryan Olson
[EMAIL PROTECTED] wrote: Bryan Olson wrote: [EMAIL PROTECTED] wrote: This message is not about the meaningless computer printout called More importantly, it's not about Python. I'm setting follow-ups to talk.politics. I set the follow-ups header appropriately, as per established newsgroup

Re: python an sqlite objects

2008-12-04 Thread Bryan Olson
[EMAIL PROTECTED] wrote: # Ensure that we're running Python 3 or later. import sys assert int(sys.version.split()[0].split('.')[0]) = 3 # If there's a better way to chek, please tell. [...] Why split at all? Just use sys.version_info: import sys assert

Re: unicode and hashlib

2008-12-02 Thread Bryan Olson
Scott David Daniels wrote: Bryan Olson wrote: ... I think that's good behavior, except that the error message is likely to end beginners to look up the obscure buffer interface before they find they just need mystring.decode('utf8') or bytes(mystring, 'utf8'). Oops, careful here (I made

Re: Reverse zip() ?

2008-12-02 Thread Bryan Olson
Zac Burns wrote: There is a problem with this however, which prompted me to actually write an unzip function. One might expect to be able to do something like so (pseudocode)... def filesAndAttributes(): files = walk() attributes = [attr(f) for f in files] return zip(files,

Re: Reverse zip() ?

2008-12-02 Thread Bryan Olson
John Machin wrote: Here's a version that makes it slightly easier to comprehend: Q: I know how to zip sequences together: | a = (1, 2, 3) | b = (4, 5, 6) | z = zip(a, b) | z | [(1, 4), (2, 5), (3, 6)] but how do I reverse the process? A: Use zip()! | a2, b2 = zip(*z) | a2 | (1, 2, 3) |

Re: Overriding a method at the instance level on a subclass of a builtin type

2008-12-02 Thread Bryan Olson
Zac Burns wrote: Sorry for the long subject. I'm trying to create a subclass dictionary that runs extra init code on the first __getitem__ call. However, the performance of __getitem__ is quite important - so I'm trying in the subclassed __getitem__ method to first run some code and then patch

Re: Obama's Birth Certificate - Demand that US presidential electors investigate Obama's eligibility

2008-12-02 Thread Bryan Olson
[EMAIL PROTECTED] wrote: This message is not about the meaningless computer printout called More importantly, it's not about Python. I'm setting follow-ups to talk.politics. Certification of Live Birth that Obama propaganda machine calls his Birth Certificate. The American people are still

Re: unicode and hashlib

2008-12-01 Thread Bryan Olson
Jeff H wrote: [...] So once I have character strings transformed internally to unicode objects, I should encode them in 'utf-8' before attempting to do things that guess at the proper way to encode them for further processing.(i.e. hashlib) It looks like hashlib in Python 3 will not even

In Python 2.6, bytes is str

2008-10-05 Thread Bryan Olson
Python 3 has the 'bytes' type, which the string type I've long wanted in various languages. Among other advantages, it is immutable, and therefore bytes objects can be dict keys. There's a mutable version too, called bytearray. In Python 2.6, the name 'bytes' is defined, and bound to str.

Re: why does socket.makefile require non-blocking mode?

2008-03-29 Thread Bryan Olson
Forest wrote: The socket.makefile() docs say, the socket must be in blocking mode. I don't see any explanation of why blocking mode is required, and I'm not sure whether that means timeout mode is forbidden as well. Can someone clarify this? Looking at the code for the existing

Re: How do I reconnect a disconnected socket?

2008-03-29 Thread Bryan Olson
Grant Edwards wrote: Laszlo Nagy wrote: What about non-blocking sockets? $ man recv ... If no messages are available at the socket, the receive calls wait for a message to arrive, unless the socket is non-blocking (see fcntl(2)), in which case the value -1 is

Re: Breaking the barrier of a broken paradigm... part 1

2008-03-25 Thread Bryan Olson
john s. wrote: #/usr/bin/enviro python #Purpose - a dropped in useracct/pass file is on a new server to build a cluster... Alas there are no home #directories.. Let me rip through the passfile, grab the correct field (or build it) and use it to make the directory! import os, sys,

Re: How to send a var to stdin of an external software

2008-03-25 Thread Bryan Olson
Benjamin Watine wrote: OK, so if I understand well what you said, using queue allow to be sure that the data is passed in totality before coninuing with next instruction. That make sense. Right. Using thread and queue seems to be very more slow than using files redirection with bash.

Re: finding items that occur more than once in a list

2008-03-23 Thread Bryan Olson
Arnaud Delobelle wrote: Bryan Olson wrote: We mean that the party supplying the keys deliberately chose them to make the hash table inefficient. In this thread the goal is efficiency; a party working toward an opposing goal is an adversary. There are situations where this can happen I

Re: Testing for an empty dictionary in Python

2008-03-23 Thread Bryan Olson
D'Arcy J.M. Cain wrote: John Nagle wrote: What's the cheapest way to test for an empty dictionary in Python? Try this: if dict: D'Arcy is right; that's the way to go. I'll add that 'dict' is the name of the built-in class, so an instance is usually best named something else. --

Re: finding items that occur more than once in a list

2008-03-22 Thread Bryan Olson
[EMAIL PROTECTED] wrote: John Machin wrote: On Mar 22, 1:11 am, [EMAIL PROTECTED] wrote: A collision sequence is not so rare. [ hash( 2**i ) for i in range( 0, 256, 32 ) ] [1, 1, 1, 1, 1, 1, 1, 1] Bryan did qualify his remarks: If we exclude the case where an adversary is choosing the

Re: How to send a var to stdin of an external software

2008-03-21 Thread Bryan Olson
Benjamin Watine wrote: [EMAIL PROTECTED] a écrit : I wrote: And here's a thread example, based on Benjamin's code: [...] Doh! Race condition. Make that: import subprocess import thread import Queue def readtoq(pipe, q): q.put(pipe.read()) cat =

Re: finding items that occur more than once in a list

2008-03-21 Thread Bryan Olson
Arnaud Delobelle wrote: Bryan Olson wrote: [...] Arnaud Delobelle offered a good Wikipedia link, and for more background look up amortized analysis. Hrvoje Niksic provided the link :). Oops, careless thread-following. Hrvoje Niksic it was. I still think two unrelated things are being

Re: What Programming Languages Should You Learn Next?

2008-03-21 Thread Bryan Olson
wesley chun wrote: http://it.slashdot.org/it/08/03/18/1633229.shtml it was surprising and disappointing that Python was not mentioned *anywhere* in that article but when someone replied, it sparked a long thread of post-discussion. What I found disappointing was how many people thought they

Re: win32: emulating select() on pipes

2008-03-18 Thread Bryan Olson
gangesmaster wrote: i'm trying to figure out if a pipe on win32 has data for me to read. [...] does anyone know of a better way to tell if data is available on a pipe? something that blocks until data is available or the timeout is elapsed, In Win32 WaitForMultipleObjects and

Re: finding items that occur more than once in a list

2008-03-18 Thread Bryan Olson
Simon Forman wrote: Is there a more efficient way to do this? def f(L): '''Return a set of the items that occur more than once in L.''' L = list(L) for item in set(L): L.remove(item) return set(L) That's neat, but quadratic time because list.remove() requires a

Re: finding items that occur more than once in a list

2008-03-18 Thread Bryan Olson
Arnaud Delobelle wrote: Ninereeds wrote: Hrvoje Niksic wrote: This doesn't apply to Python, which implements dict storage as an open-addressed table and automatically (and exponentially) grows the table when the number of entries approaches 2/3 of the table size. Assuming a good hash

Re: Convert int to float

2008-03-16 Thread Bryan Olson
sturlamolden wrote: Guido van Brakel wrote: def gem(a): g = sum(a) / len(a) return g It now gives a int, but i would like to see floats. How can integrate that into the function? You get an int because you are doing integer division. Cast one int to float. def gem(a):

Re: Socket Performance

2008-03-15 Thread Bryan Olson
[EMAIL PROTECTED] wrote: Gabriel Genellina wrote: No need to reinvent the wheel. socket objects already have a makefile method returning a file-like object, which behaves like a buffered socket. That wheel is far from round, and needs some reinvention. Python's file-like objects do not play

Re: Socket Performance

2008-03-14 Thread Bryan Olson
[EMAIL PROTECTED] wrote: [Dennis Lee Bieber had written:] Or create a protocol where the first 16 bits (in network byte order) contain a length value for the subsequent data, and use a receive process that consists of: leng = ntoh(socket.recv(2)) data = socket.receive(leng) (the

Re: Socket Performance

2008-03-14 Thread Bryan Olson
[EMAIL PROTECTED] wrote: Well, lets say you have a situation where you're going to be alternating between sending large and small chunks of data. Is the solution to create a NetworkBuffer class and only call send when the buffer is full, always recv(8192)? Buffering can often improve

Re: Spaces in path name

2008-03-14 Thread Bryan Olson
David S wrote: I get ERROR: C:\Program Files\apache-ant-1.7.0\bin\ant does not exist If I cut the path statement here and paste it next to a windows XP command prompt ant is invoked. The python code here is if not os.path.isfile(ANT_CMD): error('%s does not exist' %

Re: Spaces in path name

2008-03-14 Thread Bryan Olson
David S wrote: Using C:\Program Files\apache-ant-1.7.0\bin\ant.bat just gives me the same result. Did you try the raw string, with the .bat extension? As in: r'C:\Program Files\apache-ant-1.7.0\bin\ant.bat' After Microsoft started allowing blanks in paths, it took them years to fix many

Re: Creating a file with $SIZE

2008-03-14 Thread Bryan Olson
Robert Bossy wrote: [EMAIL PROTECTED] wrote: Robert Bossy wrote: Indeed! Maybe the best choice for chunksize would be the file's buffer size... That bit strikes me as silly. I won't search the doc how to get the file's buffer size because I'm too cool to use that function and prefer the

Re: escape string to store in a database?

2008-03-14 Thread Bryan Olson
[EMAIL PROTECTED] wrote: how would this work with UPDATE command? I get this error: cmd = UPDATE items SET content = ? WHERE id=%d % id self.cursor.execute(cmd, content) pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The c rrent statement uses 1,

Re: Creating a file with $SIZE

2008-03-14 Thread Bryan Olson
Robert Bossy wrote: Bryan Olson wrote: Robert Bossy wrote: Robert Bossy wrote: Indeed! Maybe the best choice for chunksize would be the file's buffer size... That bit strikes me as silly. The size of the chunk must be as little as possible in order to minimize

Re: Creating a file with $SIZE

2008-03-13 Thread Bryan Olson
k.i.n.g. wrote: I think I am not clear with my question, I am sorry. Here goes the exact requirement. We use dd command in Linux to create a file with of required size. In similar way, on windows I would like to use python to take the size of the file( 50MB, 1GB ) as input from user and

Re: How to send a var to stdin of an external software

2008-03-13 Thread Bryan Olson
Benjamin Watine wrote: And if somebody need it : to get the stdout in a var (myNewVar), not in the shell : cat = subprocess.Popen('cat', shell = True, stdin = subprocess.PIPE, stdout=subprocess.PIPE) cat.stdin.write(myVar) cat.stdin.close() cat.wait() myNewVar = cat.stdout.read() Is

Re: How to send a var to stdin of an external software

2008-03-13 Thread Bryan Olson
I wrote: [...] Pipe loops are tricky business. Popular solutions are to make either the input or output stream a disk file, or to create another thread (or process) to be an active reader or writer. Or asynchronous I/O. On Unix-like systems, you can select() on the underlying file

Re: What c.l.py's opinions about Soft Exception?

2008-03-09 Thread Bryan Olson
Lie wrote: [...] Soft Exception is an exception that if is unhandled, pass silently as if nothing happened. [...] Implementation: Simple implementation might be done by catching all exceptions at the highest level, then filtering which exceptions would be stopped (Soft Exception) and which

Re: Dual look-up on keys?

2008-03-06 Thread Bryan Olson
Grant Edwards wrote: It may be obvious that he has a question. It's not the least bit obvious what that question is. How can we efficiently implement an abstract data type, call it 'DoubleDict', where the state of a DoubleDict is a binary relation, that is, a set of pairs (x, y); and the

Re: Bit twiddling floating point numbers

2008-03-06 Thread Bryan Olson
Mark Dickinson wrote: Jeff Goldfin wrote: I can pack and unpack a float into a long e.g. struct.unpack('I',struct.pack('f',0.123))[0] but then I'm not sure how to work with the resulting long. Any suggestions? One alternative to using struct is to use math.ldexp and math.frexp: m, e =

Re: Python CGI Webpage with an Image

2008-03-06 Thread Bryan Olson
rodmc wrote: [...] Python: f = open(finish.html) doc = f.read() f.close() print doc You might need to start with: print Content-Type: text/html print Is finish.html in the right place? When you browse to your script, can you see that you're getting the

Re: Dual look-up on keys?

2008-03-06 Thread Bryan Olson
[EMAIL PROTECTED] wrote: Bryan Olson wrote: How can we efficiently implement an abstract data type, call it 'DoubleDict', where the state of a DoubleDict is a binary relation, that is, a set of pairs (x, y); and the operations on a DoubleDict are those on a Python set, plus

Re: Python CGI Webpage with an Image

2008-03-06 Thread Bryan Olson
rodmc wrote: [...] I have played around a bit more so that both the image and HTML file are in the public_html folder. They are called via python using a relative URL, and have permissions set to 755. Within the HTML file the image is accessed using just banner.jpg. The actual page displays

Re: URLlib2?

2008-02-28 Thread Bryan Olson
rodmc wrote: Probably a silly question but I am writing a CGI script which need to check the referring URL, can anyone provide any pointers? I have looked at URLLib2 and a couple of other libraries, but am slightly confused. When you say, check the referring URL, what are checking about it?

Re: basic threading question

2007-10-31 Thread Bryan Olson
[david] wrote: If I have 37 threads, all calling a large function 'f', are the formal parameters thread safe? That is, will the formal parameters be trashed? Do you need to use locks or semaphores before using formal parameters? Are the labels for formal parameters static? If I have

Re: transmit an array via socket

2007-10-27 Thread Bryan Olson
Hendrik van Rooyen wrote: Jeff Pang p...uno.com wrote: I want to transmit an array via socket from a host to another. How to do it? thank you. pickle it and send it and unpickle it on the other side. See the cPickle module docs for loads and dumps. In particular note: Warning: The

Re: s.split() on multiple separators

2007-09-30 Thread Bryan Olson
[EMAIL PROTECTED] wrote: Hello everyone, OK, so I want to split a string c into words using several different separators from a list (dels). I can do this the following C-like way: c=' abcde abc cba fdsa bcd '.split() dels='ce ' for j in dels: cp=[] for i in

Re: which language allows you to change an argument's value?

2007-09-30 Thread Bryan Olson
Summercool wrote: I wonder which language allows you to change an argument's value? like: foo(a) { a = 3 } n = 1 print n foo(n) # passing in n, not n print n and now n will be 3. I think C++ and PHP can let you do that, using their reference (alias) mechanism. And C,

Re: database persistence with mysql, sqlite

2007-09-27 Thread Bryan Olson
Lawrence D'Oliveiro wrote: Bryan Olson wrote: Lawrence D'Oliveiro wrote: In Bryan Olson wrote: coldpizza wrote: It turned out that the method above ('SELECT * FROM TABLE LIMIT L1, L2') works ok both with mysql and sqlite3, therefore I have decided to stick with it until I find something

Re: sorteddict PEP proposal [started off as orderedict]

2007-09-27 Thread Bryan Olson
Mark Summerfield wrote: The sorteddict API that has emerged so far is (1) apart from the constructor, everything is identical to dict, (2) the constructor takes the same args as sorted(), so if you want to seed with a dict or with keywords you write sorteddict(dict(a=1,b=2), ...), (or you

Load balancing and passing sockets; was: Re: Google and Python

2007-09-27 Thread Bryan Olson
Hendrik van Rooyen wrote: Nick Craig-Wood wrote: [about passing sockets between processes] It is trivial to pass a socket to a new thread or a forked child - you don't need this mechanism for that. It doesn't work on different machines though - it has to be on the same machine. How does a

Re: database persistence with mysql, sqlite

2007-09-26 Thread Bryan Olson
coldpizza wrote: It turned out that the method above ('SELECT * FROM TABLE LIMIT L1, L2') works ok both with mysql and sqlite3, therefore I have decided to stick with it until I find something better. With Sqlite3 you are supposed to use LIMIT 10 OFFSET NN, but it also apparently supports the

Re: database persistence with mysql, sqlite

2007-09-26 Thread Bryan Olson
Lawrence D'Oliveiro wrote: In Bryan Olson wrote: coldpizza wrote: It turned out that the method above ('SELECT * FROM TABLE LIMIT L1, L2') works ok both with mysql and sqlite3, therefore I have decided to stick with it until I find something better. With Sqlite3 you are supposed to use

Re: Google and Python

2007-09-25 Thread Bryan Olson
Alex Martelli wrote: Bryan Olson [EMAIL PROTECTED] wrote: ... YouTube (one of Google's most valuable properties) is essentially all-Python (except for open-source infrastructure components such as lighttpd). Also, at Google I'm specifically Uber Tech Lead, Production Systems: while I

Re: Google and Python

2007-09-25 Thread Bryan Olson
Paul Rubin wrote: You can also pass the open sockets around between processes instead of reverse proxying, using the SCM_RIGHTS message on Unix domain sockets under Linux, or some similar mechanism under other Unixes (no idea about Windows). Python does not currently support this but one of

Re: Google and Python

2007-09-24 Thread Bryan Olson
Alex Martelli wrote: Bryan Olson wrote: [...] How does Google use Python? As their scripting-language of choice. A fine choice, but just a tiny little piece. Maybe Alex will disagree with me. In my short time at Google, I was uber-nobody. YouTube (one of Google's most valuable properties

Re: database persistence with mysql, sqlite

2007-09-23 Thread Bryan Olson
coldpizza wrote: I want to run a database query and then display the first 10 records on a web page. Then I want to be able to click the 'Next' link on the page to show the next 10 records, and so on. My question is how to implement paging, i.e. the 'Next/Prev' NN records without

Re: Getting rid of bitwise operators in Python 3?

2007-09-22 Thread Bryan Olson
Carl Banks wrote: Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not often done in Python because of keyword arguments and dicts, which are lot more versatile. Another major use, talking to hardware, is not something oft done in Python

Re: Would Anonymous Functions Help in Learning Programming/Python?

2007-09-22 Thread Bryan Olson
[EMAIL PROTECTED] wrote: There are already anonymous functions in Python. lambda x, y, z: x + y + z is the same as: def _(x, y, z): return x + y + z They are the same only in special cases: The special identifier _ is used in the interactive interpreter to store the result of

Re: Would Anonymous Functions Help in Learning Programming/Python?

2007-09-22 Thread Bryan Olson
Cristian wrote: [...] Specifically, he's having trouble thinking of functions as first order data (don't worry, I haven't confused him with such terminology yet). [...] And, after we finally get a hold of first order functions, we appreciate its incorporation into languages. It would be a

Re: Would Anonymous Functions Help in Learning Programming/Python?

2007-09-22 Thread Bryan Olson
Paul Rubin wrote: Bryan Olson [EMAIL PROTECTED] writes: [EMAIL PROTECTED] wrote: There are already anonymous functions in Python. lambda x, y, z: x + y + z is the same as: def _(x, y, z): return x + y + z They are the same only in special cases: The special identifier _ is used

Re: Getting rid of bitwise operators in Python 3?

2007-09-22 Thread Bryan Olson
[EMAIL PROTECTED] wrote: Bryan Olson wrote: One surprising result was that more of the Python programmers surveyed use bitwise operators than are aware of the exponentiation operator, which C does not offer. On that subject, I'd suggest that the pow() builtin (not the ** operator - just

Re: Sets in Python

2007-09-21 Thread Bryan Olson
Gabriel Genellina wrote: En Thu, 20 Sep 2007 08:46:29 -0300, Steven D'Aprano Another way is to use this class: class HashableList(list): def __hash__(self): return hash(tuple(self)) ...and that will stop working as soon as the list is mutated (which is exactly what you

Re: Google and Python

2007-09-20 Thread Bryan Olson
TheFlyingDutchman asked of someone: Would you know what technique the custom web server uses to invoke a C++ app No, I expect he would not know that. I can tell you that GWS is just for Google, and anyone else is almost certainly better off with Apache. (ditto for Java and Python) CGI is

Re: Sets in Python

2007-09-19 Thread Bryan Olson
Karthik Gurusamy wrote: While it's easy to explain the behavior, I think the decision to dis- allow mutable items as keys is a bit arbitrary. Furthermore, it's not really true. class Blurf (object): def __init__(self, intval): self.seti(intval) def

Re: The meaning of a = b in object oriented languages

2007-09-18 Thread Bryan Olson
Jim Langston wrote: Assignment operators in C++ should attempt to prevent two pointers poining to the same memory location. Consier a simple class (untested): class Foo { public: char* Data; int DataSize; Foo( int Size ): DataSize( Size ) { Data = new char[Size]; } ~Foo()

Re: can Python be useful as functional?

2007-09-18 Thread Bryan Olson
Rustom Mody asked: [...] why does (yield(x) for x in si(l) if x % p != 0) not work? I would have expected generator expression to play better with generators. You have a statement, yield(x), where the construct requires an expression. -- --Bryan --

Re: Coming from Perl

2007-09-17 Thread Bryan Olson
Amer Neely wrote: I don't have shell access but I can run 'which python' from a Perl script, and I will try the different shebang line you suggested. And after trying it, Amer Neely reported: I tried `which python` and `whereis python` and got 0 back as a result. So it seems Python is not

Re: Modul (%) in python not like in C?

2007-09-15 Thread Bryan Olson
J. Cliff Dyer wrote: Bryan Olson wrote: Scott David Daniels wrote: C, which was designed as a high level assembly language, does not tightly define the results of / and % for negative numbers. Instead it defines the result for positive over positive, and constrains the result

Re: Possible suggestion for removing the GIL

2007-09-14 Thread Bryan Olson
Prateek wrote: [...] Mainly it revolves around dedicating one core for executing synchronized code and doing context switches instead of acquiring/ releasing locks. http://www.brainwavelive.com/blog/index.php?/archives/12-Suggestion-for-removing-the-Python-Global-Interpreter-Lock.html

Re: Coming from Perl

2007-09-14 Thread Bryan Olson
Amer Neely wrote: This seems to indicate that maybe my host needs to configure Apache to run python scripts? But I didn't need to do anything with mine. Another possibility: If it works on Windows but not Unix, check the end-of-line characters. Windows ends each line with the two character

  1   2   3   4   >