Re: Determin network interface

2006-10-02 Thread Bryan Olson
[EMAIL PROTECTED] wrote: > Hi. How can I determin the hwaddr or ipaddress of the networkinterface > that is used in an outgoing connection? Is sock_object.getsockname() enough? http://docs.python.org/lib/socket-objects.html -- --Bryan -- http://mail.python.org/mailman/listinfo/python-lis

Re: working with files and directories

2006-11-27 Thread Bryan Olson
halex2000 wrote: > Hi all, I'm new with Python, and I thought to use it to automatically rename > some files in a directory, but I don't know where should I search the > functions: to get all the files of a directory, to rename the files and so > on. Python programmers are constantly looking at

Re: Some thougts on cartesian products

2006-01-22 Thread Bryan Olson
Christoph Zwerschke wrote: > In Python, it is possible to multiply a string with a number: > > >>> "hello"*3 > 'hellohellohello' Which is really useful. > However, you can't multiply a string with another string: > > >>> 'hello'*'world' > Traceback (most recent call last): > File "", line 1

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Christoph Zwerschke wrote: [...] > That may be the main problem to decide whether the cartesian product > should return a generator or a list. The Cartesion product is a set. [...] > That's the other problem. The uses cases (like the password cracker > example) are very limited and in these cas

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Steven D'Aprano wrote: > Bryan Olson wrote: >>Christoph Zwerschke wrote: >>[...] >> >>>That may be the main problem to decide whether the cartesian product >>>should return a generator or a list. >> >>The Cartesion product is a set. >

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Steven D'Aprano wrote: > Bryan Olson wrote: > > [Christoph Zwerschke had written:] >>>What I expect as the result is the "cartesian product" of the strings. >> >>There's no such thing; you'd have to define it first. Are duplicates >>s

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Steven D'Aprano wrote: > On Mon, 23 Jan 2006 18:17:08 +0000, Bryan Olson wrote: > > >>Steven D'Aprano wrote: >> >>>Bryan Olson wrote: >>> >>[Christoph Zwerschke had written:] >> >>>>>What I expect as the result is the &q

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Kay Schluehr wrote: > Bryan Olson wrote: > > >>There's no such thing; you'd have to define it first. Are duplicates >>significant? Order? > > > That's all trivial isn't it? A string is a set of pairs (i,c) where i > is an integer number, t

Re: list comprehention

2006-01-23 Thread Bryan Olson
Bryan Olson wrote: > Duncan Booth wrote: > >> Here's the way I would do it: >> >>>>> def occurrences(it): >> >> >> res = {} >> for item in it: >> if item in res: >> res[item] += 1 >>

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Christoph Zwerschke wrote: > Bryan Olson schrieb: > >>> Still think there is no such thing? >> >> >> Uh, yes. >> >>The Cartesian product of two sets A and B (also called the >>product set, set direct product, or cross product) is defi

Re: socket examples

2006-01-24 Thread Bryan Olson
le dahut wrote: > I have a server that receives data from a client, detect the end of this > data and send other data back to the client (it's to measure bandwidth). > I think the best way is to thread a part of the server's program am I > right ? Others disagree on this, but in most cases, yes:

Re: Some thougts on cartesian products

2006-01-24 Thread Bryan Olson
Christoph Zwerschke wrote: > Bryan Olson wrote: > >> The claim "everything is a set" falls into the category of >> 'not even wrong'. > > No, it falls into the category of the most fundamental Mathematical > concepts. You actually *define* tuples a

Re: socket examples

2006-01-24 Thread Bryan Olson
le dahut wrote: > I've read the Gordon McMillan's "Socket Programming HOWTO" Just a few days ago, another participant in this group noted that code in Gordon McMillan's "Socket Programming HOWTO" does not work. He was right. The code is wrong. Currently, one can Google up "Python socket howto",

Re: Thread imbalance

2006-02-06 Thread Bryan Olson
Tuvas wrote: > The stuff that it runs aren't heavily processor intensive, but rather > consistant. It's looking to read incoming data. For some reason when it > does this, it won't execute other threads until it's done. Hmmm. > Perhaps I'll just have to work on a custom read function that doesn't >

Re: Thread imbalance

2006-02-06 Thread Bryan Olson
Peter Hansen wrote: > Ivan Voras wrote: >> Python is bad for concurrently executing/computing threads, but it >> shouldn't be that bad - do you have lots of compute-intensive threads? > > Just in case anyone coming along in the future reads this statement, for > the record I'd like to say this i

Re: Thread imbalance

2006-02-06 Thread Bryan Olson
Tuvas wrote: > The read function used actually is from a library in C, for use over a > CAN interface. The same library appears to work perfectly find over C. [...] > When nothing is happening, the thread runs pretty consistantly at 1 > second. However, when it is doing IO through this C function o

Re: threads and memory

2006-02-06 Thread Bryan Olson
Lee Leahu wrote: > I am trying to write a simple threaded application which will > simulate 1000 connections to a remote service in order to > stress test" that the remote service can handle that many > connections. That shouldn't be a problem on a modern OS, but there are still quite a few not

Re: Question about idioms for clearing a list

2006-02-07 Thread Bryan Olson
Fredrik Lundh wrote: > Steven D'Aprano wrote: [...] >>del L[:] works, but unless you are Dutch, it fails the >>obviousness test. > > > unless you read some documentation, that is. del on sequences > and mappings is a pretty fundamental part of Python. so are slicings. So is consistency; it ain

Re: Too Many if Statements?

2006-02-07 Thread Bryan Olson
Alan Morgan wrote: > slogging_away wrote: > >>Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 >>32 bit (Intel)] on win32, and have a script that makes numerous checks >>on text files, (configuration files), so discrepancies can be reported. >>The script works fine but it app

Re: Question about idioms for clearing a list

2006-02-07 Thread Bryan Olson
Fredrik Lundh wrote: > Bryan Olson wrote: > > >>So is consistency; it ain't Perl, thank Guido. > > consistency is the hobgoblin of little minds. Look up that saying. Any clues? >>Python now has, what, three built-in mutable collections types: >>lists,

Re: Too Many if Statements?

2006-02-07 Thread Bryan Olson
Terry Reedy wrote: > "Bryan Olson" wrote: > >>I made a script with 100,000 if's, (code below) and it appears >>to work on a couple systems, including Python 2.4.2 on Win32-XP. >>So at first cut, it doesn't seem to be just the if-count that >>tri

Re: Question about idioms for clearing a list

2006-02-08 Thread Bryan Olson
Magnus Lycka wrote: > Ed Singleton wrote: > >> The point is that having to use del to clear a list appears to the >> inexperienced as being an odd shaped brick when they've already used >> the .clear() brick in other places. > > > Agreed. The smart way to go from this stage of surprise is > not

Re: Threads and Interpreter death

2006-02-09 Thread Bryan Olson
Rene Pijlman wrote: > Carl J. Van Arsdall: > >>I've been toying with threads a lot lately and I've noticed that if a >>scripting error occurs in a thread the thread dies, but not the process >>that spawned the thread. >> >>Is python supposed to behave this way or is this type of behavior >>acci

Re: Question about idioms for clearing a list

2006-02-09 Thread Bryan Olson
Magnus Lycka wrote: > Bryan Olson wrote: > >> The original question was about idioms and understanding, but >> there's more to the case for list.clear. Python is "duck typed". >> Consistency is the key to polymorphism: type X will work as an >> actua

Re: Question about idioms for clearing a list

2006-02-10 Thread Bryan Olson
Magnus Lycka wrote: > Bryan Olson wrote: > >> Magnus Lycka wrote: >> >>> Do you really have a usecase for this? It seems to me that your >>> argument is pretty hollow. >> >> >> Sure: >> >> if item_triggering_end in colle

Re: Question about idioms for clearing a list

2006-02-10 Thread Bryan Olson
Raymond Hettinger wrote: [...] > If you're asking why list's don't have a clear() method, the answer is > that they already had two ways to do it (slice assignment and slice > deletion) and Guido must have valued API compactness over collection > polymorphism. That's a decision from long ago. Now

Re: Question about idioms for clearing a list

2006-02-10 Thread Bryan Olson
Magnus Lycka wrote: > Bryan Olson wrote: > >> Magnus Lycka wrote: >> >>> Bryan Olson wrote: >>> >>>> big_union = set() >>>> for collection in some_iter: >>>> big_union.update(t) >>>> colle

Re: Is empty string cached?

2006-02-15 Thread Bryan Olson
Farshid Lashkari wrote: > When I pass an empty string to a function is a new string object created > or does python use some global pre-created object? I know python does > this with integer objects under a certain value. For instance, in the > following code is a new string object created for e

Re: is socket thread safe?

2006-02-15 Thread Bryan Olson
[EMAIL PROTECTED] wrote: > thread1: > while 1: > buf = s.read() > process(buf) > > thread2: > while 1: > buf = getdata() > s.write(buf) Sockets don't have read() and write() methods. Connected sockets have recv() and send()/sendall(). Python's socket module

Re: is socket thread safe?

2006-02-15 Thread Bryan Olson
Carl J. Van Arsdall wrote: > Steve Horsley wrote: > >> [EMAIL PROTECTED] wrote: >> >> >>> thread1: >>> while 1: >>> buf = s.read() >>> process(buf) >>> >>> thread2: >>> while 1: >>> buf = getdata() >>> s.write(buf) >> >> >> It is safe, but watch out fo

Re: %SystemDrive%

2006-02-15 Thread Bryan Olson
rtilley wrote: > Carsten Haese wrote: > >> Is there a reason why os.environ['SYSTEMDRIVE'] shouldn't work? > > I didn't know it was in os! It returns C: instead of C:\ like my method. > Other than that, it seems to do the trick. To get it with the \, you might use: os.path.abspath(os.envi

Re: Databases and python

2006-02-16 Thread Bryan Olson
Dan Stromberg wrote: > I've been putting a little bit of time into a file indexing engine [...] > So far, I've been taking the approach of using a single-table database > like gdbm or dbhash [...] and making each entry keyed by > a word, and under the word in the database is a null terminated list

Re: %SystemDrive%

2006-02-16 Thread Bryan Olson
Atanas Banov wrote: > Bryan Olson wrote: > >>To get it with the \, you might use: >> >> os.path.abspath(os.environ['SYSTEMDRIVE']) > > > wrong! > the result is incorrect if the current directory is different from the > root. Oops, sorry. I

Re: Databases and python

2006-02-17 Thread Bryan Olson
Dan Stromberg wrote: > Bryan Olson wrote: [...] >> Well, you could use simple files instead of fancy database tables. > > That's an interesting thought. Perhaps especially if australopithecine > were saved in a filename like: > > ~/indices/au/st/ra/lo/pi/th/ec/in

Re: Databases and python

2006-02-20 Thread Bryan Olson
Dan Stromberg wrote: > I've been putting a little bit of time into a file indexing engine [...] To solve the O.P.'s first problem, the facility we need is an efficient externally-stored multimap. A multimap is like a map, except that each key is associated with a collection of values, not just a s

Re: time.sleep(1) sometimes runs for 200 seconds under windows

2006-02-24 Thread Bryan Olson
Paul Probert wrote: [...] > Its happening roughly 4 times a day total on our 20 machines, ie about > once every 5 days on a given machine. Do they all have similar anti-virus programs? Some of those can freeze out other tasks from time to time. Just one more candidate. -- --Bryan -- http://ma

Re: Multiple threaded download streams?

2006-02-25 Thread Bryan Olson
Diez B. Roggisch wrote: >> Use a separate thread for downloading. > > Or the twisted select-reactor. No threads needed. He's using urllib2, which does not use Twisted's select-reactor. Fortunately urllib2 downloads run fine in their own threads; no rewrite-all-the-code-as-Twisted-state-machines

Re: Is Python a Zen language?

2006-02-25 Thread Bryan Olson
John Coleman wrote: >I have a rough classification of languages into 2 classes: Zen > languages and tool languages. A tool language is a language that is, > well, a *tool* for programming a computer. C is the prototypical tool > language. Most languages in the Algol family are tool languages. V

Re: Random Prime Generator/Modular Arithmetic

2006-03-05 Thread Bryan Olson
Tuvas wrote: > Okay, I don't know if your farmiliar with the miller-rabin primality > test, Paul is familiar with it. When he referred to your Miller-Rabin test, he meant all the rounds. > but it's what's called a probabalistic test. Meaning that trying > it out once can give fake results. In t

Re: Random Prime Generator/Modular Arithmetic

2006-03-05 Thread Bryan Olson
Tuvas wrote: [...] > Actually, I did another test, and realized that it was indeed a bug in > the code. Yikes. Oh well, thanks for the help in identifying it! > > An example that would be alot easier is this: > Mod(16,561).is_strong_pseudo_prime() > > True Hmmm...my M-R tester disagrees...

Re: Question re client/server and blocking

2006-03-05 Thread Bryan Olson
Frank Millman wrote: [...] > There is a server component and a client component. All the business > logic is performed on the server. Oh, what a give-away. If the logic is in the server, then the client component should probably be the user's chosen web browser. > The client communicates with

Re: Cryptographically random numbers

2006-03-06 Thread Bryan Olson
Tuvas wrote: > Okay, I'm working on devoloping a simple, cryptographically secure > number, from a range of numbers (As one might do for finding large > numbers, to test if they are prime). My function looks like this: > > def cran_rand(min,max): > if(min>max): > x=max > max=mi

Re: Random Prime Generator/Modular Arithmetic

2006-03-06 Thread Bryan Olson
Tuvas wrote: > Okay, now I get the correct number of 561 pseudoprimes, 5, so I can > assume that it is indeed working right. Your code now looks right, so I'm guessing "5" was a typo, perhaps because "5" is just below "8" on the numeric keypad. You can simplify your loop like: def is_strong_pse

Re: spliting on ":"

2006-03-06 Thread Bryan Olson
Peter Hansen wrote: > The archives could tell you more, but basically on is usually interested > in *identity* with a singleton object (None), not in whether the object > on is examining happens to compare equal. A custom object could be > designed to compare equal to None in certain cases, eve

Re: Cryptographically random numbers

2006-03-06 Thread Bryan Olson
Paul Rubin wrote: > My favorite way to convert strings to numbers is with binascii: > > from binascii import hexlify > def s2num(text): >return int(hexlify(text), 16) Neat. I use the empty string as a binary representation of zero, which you can accommodate with: def s2num(text): ret

Re: The Future of Python Threading

2007-08-11 Thread Bryan Olson
Justin T. wrote: > True, but Python seems to be the *best* place to tackle this problem, > at least to me. It has a large pool of developers, a large standard > library, it's evolving, and it's a language I like :). Languages that > seamlessly support multi-threaded programming are coming, as are >

Re: python socket usage

2007-08-17 Thread Bryan Olson
Oğuz Yarımtepe wrote: > As i read pickle module is Python-spesific. I need to talk with a Java > application and get the infortion that it will send. What i do right now is > listening a socket and reding the string that is sent by the java > application. So the java application is sending a str

Re: Development for dual core machine

2007-08-19 Thread Bryan Olson
Andy wrote: > I'm going to develop a software package that includes a web server > (and PHP code) , a database, and some Python code of course. I am > being strongly suggested to make it to work on a dual- or multi-core > computer, but I'm confused on how to take advantage of the multiple > CPUs.

Re: Socket recv(1) seems to block instead of returning end of file.

2007-08-23 Thread Bryan Olson
Grant Edwards wrote: [...] > import socket,random > > HOST = '' # Symbolic name meaning the local host > PORT = 8765 # Arbitrary non-privileged port > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.connect((HOST, PORT)) Actually the empty string passed for

Re: status of Programming by Contract (PEP 316)?

2007-09-01 Thread Bryan Olson
Steve Holden wrote: [...] > If I can blow my own trumpet briefly, two customers (each using over 25 > kLOC I have delivered over the years) ran for two years while I was away > in the UK without having to make a single support call. One of the > systems was actually locked in a cupboard all that

Re: So what exactly is a complex number?

2007-09-02 Thread Bryan Olson
Tim Daneliuk wrote: > Grzegorz Słodkowicz wrote: [...] >> You're mixing definition with application. You didn't say a word about >> what complex numbers are, not a word about the imaginary unit, where > > I was trying to motivate the idea by means of analogy. This is a > legitimate thing to do.

Re: How can I wait for all the threads I spawn for 5 minutes

2007-09-02 Thread Bryan Olson
herman wrote: > In my python program, I would to like to spwan 5 threads, for the them > for 5 minutes maximum and the continue. Here is my script: > > threads = [] > > for j in range(5): > t = MyThread() > threads.append(t) > >

Re: Python is overtaking Perl

2007-09-05 Thread Bryan Olson
The expression "faint praise" comes to mind. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list

Re: creating really big lists

2007-09-05 Thread Bryan Olson
Paul Rudin wrote: > Dr writes: >> I would like to create a pretty big list of lists; a list 3,000,000 >> long, each entry containing 5 empty lists. My application will append >> data each of the 5 sublists, so they will be of varying lengths (so no >> arrays!). >> >> Does anyone know the most effic

Re: Does shuffle() produce uniform result ?

2007-09-08 Thread Bryan Olson
Paul Rubin wrote: > Lawrence D'Oliveiro writes: >> Except that the NSA's reputation has taken a dent since they failed to >> anticipate the attacks on MD5 and SHA-1. > > NSA had nothing to do with MD5, and it's to NSA's credit that SHA-1 > held up for as long as it did. I haven't kept up. Has any

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

2007-09-09 Thread Bryan Olson
Arnau Sanchez wrote: >> Dotan Cohen wrote: >>> Second, in Turbo C -111%10=-1 however in python -111%10=9. Is one or >>> the other in error? Is this a known gotcha? I tried to google the >>> subject however one cannot google the symbol %. Thanks in advance. [...] > In fact, what you get in C depend

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

2007-09-09 Thread Bryan Olson
Dotan Cohen wrote: > On 10/09/2007, Bryan Olson <[EMAIL PROTECTED]> wrote: >> Not according to the C standard: >> >> When integers are divided, the result of the / operator is >> the algebraic quotient with any fractional part discarded.(87) >>

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

2007-09-09 Thread Bryan Olson
Dotan Cohen wrote: > FIrst of all, how is the % symbol (as in 70%6=4) called in English? The operator is usually called "mod". (The symbol is usually called "percent".) I reserve "modulo" for its usage in mathematics. 70 modulo 6 is an equivalence class containing infinitely many integers. In mat

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

2007-09-10 Thread Bryan Olson
Dennis Lee Bieber wrote: > The best answer is probably to be found from the definition of > divmod() The divmod() function is one of those little delights that reminds me why I love Python, but I do not think it answers the question here. The definition of divmod() references the '%' operati

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

2007-09-10 Thread Bryan Olson
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 for the others. Not true. Here it is again:

Re: multithreading concept

2007-03-08 Thread Bryan Olson
sturlamolden wrote: [...] > If you want to utilize the computing power of multiple CPUs, you > should use multiple processes instead of threads. On Python this is > mandatory due to the GIL. In any other language it it highly > recommended. The de-factor standard for parallel multiprocessing (MPI)

Re: socket read timeout

2007-04-01 Thread Bryan Olson
Steve Holden wrote: > Hendrik van Rooyen wrote: >> Are sockets full duplex? >> > Yes. But you have to use non-blocking calls in your application to use > them as full-duplex in your code. Hmmm... I'm missing something. Suppose I have one thread (or process) reading from a blocking-mode socket whi

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 C

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 se

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 r

Re: Coming from Perl

2007-09-16 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 n

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]; } >

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 -- http://mail.python.org/mailma

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 seti(se

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 s

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 > exact

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 Pyt

Re: Zope review

2007-09-22 Thread Bryan Olson
Sean Tierney wrote: >>From Twisted's website "Twisted is a networking engine written in > Python, supporting numerous protocols. It contains a web server, > numerous chat clients, chat servers, mail servers, and more. > > Given that Zope is also a written in python, supports numerous > protocols,

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 r

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 b

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 >> The

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

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 reestab

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. &

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

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 o

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 >

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

Re: database persistence with mysql, sqlite

2007-09-26 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, >>>>

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 c

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. > >

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 i

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) mechan

Re: transmit an array via socket

2007-10-27 Thread Bryan Olson
Hendrik van Rooyen wrote: > "Jeff Pang" 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 p

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

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

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 ope

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.fr

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 getti

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 Doubl

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 disp

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 w

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 an

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

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 descr

<    1   2   3   4   >