Re: time module precision

2005-01-10 Thread janeaustine50
Peter Hansen wrote:
> [EMAIL PROTECTED] wrote:
> > So the problem (waiting tens to hundreds of us without busy
looping)
> > still remains...
>
> That's actually not a "problem", it's your solution
> to a problem.  Can you describe the _real_ problem, what
> you are trying to do?  _Why_ do you want to wait such
> brief amounts of time?
>
> I ask as someone with fairly extensive background in
> realtime software (which is basically what it sounds like
> you are trying to write here), and I suspect that you are
> either trying to achieve something that's not really possible
> on Windows XP, or that you are simply doing something that
> is entirely unnecessary, probably for good reasons but
> with too little experience of the issues involved.  Can
> you expand on your situation?
>
> -Peter

What I am trying to do is sending binary data to a serial port. Since
the device attached to the port cannot handle a continous in-flow of
data, I need to make an artificial tiny delay in-between data chunks(a
few hundreds of KBs). The delay might be a few tens to hundreds of us.

I'd like to make the transmission as fast as possible, uh.. well..
reasonably fast.

[I sort of posted this already but hasn't got it through so am
reposting it now]

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-10 Thread Terry Reedy

"Andrey Tatarinov" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> How does GvR suggestions on removing map(), reduce(), filter()

While GvR *might* prefer removing them completely on any given day, I think 
moving them to a functional module, as others have suggested and requested, 
is currently more likely.  I believe that GvR has indicated at times that 
this would be an acceptible compromise.

I am one of those who think the list of builtins is currently too long to 
be easily grasped and should be shrunk.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Long strings as function parameters

2005-01-10 Thread Terry Reedy

"Dan Bishop" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> In Python, *every* expression is a pointer.

Minor but to me important nit: this should start "In the CPython 
implementation of Python" ...

Humans can understand and execute Python code without knowing about 
computer memory addresses (pointers).  Other computer languages can also do 
something slightly different from CPython, as I believe is the case with 
Jython.

The Python language is defined by sematics, not by mechanisms, especially 
low-level interpreter-specific mechanisms.  This is a large part of what 
makes it readable.

To the OP: a Python function call binds argument objects to either local 
parameter names or slots within a named catchall list or dict.  Like other 
binding (assignment) operations, there is no copying.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SuSE 9.1: updating to python-2.4

2005-01-10 Thread David Fraser
Torsten Mohr wrote:
Hi,
along with my distribution SuSE 9.1 came python 2.3.3.
I'd like to update to 2.4 now, is this an easy thing to do
or will lots of installed modules refuse to work then?
Is there an easy way to find out what i need to update?
Thanks for any hints,
Torsten.
What you probably want to do is install python2.4 alongside python2.3.3 
as an alternate installation, since a lot of other programs in SuSE 
probably depend on having python2.3.3 and won't work with the upgrade.

Have a look at the RPMs on the python 2.4 downloads page and see if you 
can install them OK (I just did this fine for python 2.3 on whitebox linux).

David
--
http://mail.python.org/mailman/listinfo/python-list


Re: raw sockets ? i need a python sniffer

2005-01-10 Thread lbolognini
Would this suit you?
http://www.nullcube.com/software/pyopenbsd.html

Lorenzo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-10 Thread Duncan Booth
Nick Coghlan wrote:

> Grammar Change
> --
> Current::
>statement ::=stmt_list NEWLINE | compound_stmt
> 
> New::
>statement ::=(stmt_list NEWLINE | compound_stmt) [local_namespace]
>local_namespace ::= "with" ":" suite
> 
> 
> Semantics
> -
> The code::
> 
> with:
> 
> 
> translates to::
> 
> def unique_name():
>  
>  
> unique_name()
> 

Your proposed grammar change says that you need a newline after the 
statement:

statement
with:
suite

e.g.

res = [ f(i) for i in objects ]
with:
def f(x):
pass

or

for i in objects:
f(i)
with:
def f(x):
   pass
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Jacek Generowicz
"Anna" <[EMAIL PROTECTED]> writes:

> With class and def, I at least have a *name* to start with - class
> Square pretty obviously is going to have something to do with
> geometric shapes, I would hope (or maybe with boring people...).

Or maybe with multiplying something by itself. Or maybe the author
made some changes in his program, and forgot to rename the class
sensibly, and the class' functionality has nothing to do with squares
of any sort any more. Or maybe he felt the name "Square" was very
appropriate for something else in his program and inadvertently gave
the same name to two different entities thereby clobbering the one
whose use was intended at this point.

> def getfoo() tells me I'm the function is likely to go elsewhere and
> get something. It's a *start*,

All too often a start in the wrong direction.

> a handle, to deciphering whatever the following statements are
> doing. (Yes, I realize that often class and function names suck

Yup. I waste quite some time because of crappily chosen names.

> - but more often than not, they give *some* clue).
> 
> Whereas, with lambda - I have *nothing* to go on.

Aaah. OK, you object to lambda because it gives you no clue as to what
the function does, rather than with the word "lambda" itself? Is that
it?

So, IIUC, you consider

   def add_one(x):
   return x+1
   
   map(add_one, seq)

to be clearer than

   map(lambda x:x+1, seq)

?

> With lambdas, all I know is that the programmer wanted to hide
> whatever it is the program is doing behind the curtain...

I find this a strange way of looking at it, given that, with lambda,
what the program is doing is right there in front of your very eyes at
the very point at which it is doing it. Were there a name, _then_ you
could argue that the functionality is hidden ... and you would have to
look the name up, to make sure that it really represents what you
inferred it meant (and, to be absolutely sure, you'd have to double
check that it hasn't been rebound by some other part of the program in
some nasty way). None of these problems arise with lambda.

> IMHO, YMMV, etc etc

Of course. Same here.

> Personally, I like lambdas less than regular expressions (of which
> I'm particularly UNfond but understand their usefulness at
> times). At least with regular expressions - I know that the
> gibberish I need to decipher (probably) has to do with text
> parsing...

Hmm, that tells you about as much as lambda does. With lambda you know
that the gibberish you need to decipher has to do with functions :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Jacek Generowicz
Nick Coghlan <[EMAIL PROTECTED]> writes:

> > Usually one or two have trouble grasping that "int" would be perfectly
> > adequate in this situation.
> 
> The ability to pass around functions at run-time was probably the
> hardest thing to get my head around when I started with Python,

And I suspect that this particular case is further complicated by the
fact that int is not a function ... it's a type!

I can imagine it might make a newbie's brain melt. Still, most of them
survive and thoroughly enjoy the course :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SuSE 9.1: updating to python-2.4

2005-01-10 Thread Wolfram Kraus
Heyho!
Torsten Mohr wrote:
Hi,
along with my distribution SuSE 9.1 came python 2.3.3.
I'd like to update to 2.4 now, is this an easy thing to do or will
lots of installed modules refuse to work then?
I installed Python 2.4 under SuSE 9.1 and had no problems so far. If you
install it via "./configure;make;make install", python 2.4 will be
installed in /usr/local/lib/python2.4 parallel to your existing 2.3
installation under /usr/lib/python2.3.
Is there an easy way to find out what i need to update?
Just check out, which version comes up when you call "python" from the 
shell. If this is version 2.3 you can start 2.4 with "python2.4"
All the installed packages for python2.3 (e.g. PIL, MySQLdb, wxPython,
...) need to be installed for the new version, too.
Thanks for any hints, Torsten.
HTH,
Wolfram
--
http://mail.python.org/mailman/listinfo/python-list


Old Paranoia Game in Python

2005-01-10 Thread Sean P.Kane
I ported the old (and long since removed) game from the bsd-game 
pacakge called, Paranoia, based on the old Paranoia role playing game 
from C to Python as a simple exercise in learning the language and pure 
late night boredom. Anyways, here it is for anyone looking for a few 
minutes of nostalgia. I may get around to posting this at 
http://homepage.mac.com/spkane/ or http://www.spkane.org/, but for now 
here it is. Improvements or corrections, welcome.

Thanks,
Sean
-Cut Here-
#!/usr/bin/env python
#
#
# -*- encoding = 'utf-8' -*-
#
#
# Command Line GCS Upgrade Application
# 
# This is a port of paranoia from the old bsd-games package.
#
#
# HISTORY
# ===
#
# 1.2 - 03 Jan 2005
# + Initially started porting application
#
# Requires
# 
# 1) Python 2.3
'''\
usage: paranoia
'''
__author__ = 'Sean P. Kane <[EMAIL PROTECTED]>'
__copyright__  = '''This is a solo paranoia game taken from the Jan/Feb 
issue (No 77) of SpaceGamer/FantasyGamer magazine.

Article by Sam Shirley.
Originally implemented in C on Vax 11/780 under UNIX by Tim Lister
Ported to Python on an Apple Powerbook G4 by Sean P. Kane
This is a public domain adventure and may not be sold for profit'''
__date__  = '01/03/2005'
#Also change version at top of main()
__version__= '1.2'
#the basics
import sys
#For Dice Rolling
import random
#new argument parsing library
from optparse import OptionParser
moxie = 13
agility = 15
maxkill = 7 # The maximum number of UV's you can kill
clone = 1
page = 1
computer_request = 0
ultra_violet = 0
action_doll = 0
hit_points = 10
read_letter = 0
plato_clone = 3
blast_door = 0
killer_count = 0
def instructions():
   print """Welcome to Paranoia!
HOW TO PLAY:
   Just press  until you are asked to make a choice.
   Select 'a' or 'b' or whatever for your choice, then press .
   You may select 'p' at any time to get a display of your statistics.
   Always choose the least dangerous option.  Continue doing this until
   you win. At times you will use a skill or engage in combat and will
   be informed of the outcome.  These sections will be self explanatory.
   HOW TO DIE:
   As Philo-R-DMD you will die at times during the adventure.
   When this happens you will be given an new clone at a particular
   location. The new Philo-R will usually have to retrace some of
   the old Philo-R\'s path hopefully he won\'t make the same mistake
   as his predecessor.
   HOW TO WIN:
   Simply complete the mission before you expend all six clones.
   If you make it, congratulations.
   If not, you can try again later.
"""
def character():
   print 
===
The 

The Character : Philo-R-DMD %s
Primary Attributes  Secondary Attributes
===
Strength . 13   Carrying Capacity . 30
Endurance  13   Damage Bonus ... 0
Agility .. 15   Macho Bonus ... -1
Manual Dexterity . 15   Melee Bonus .. +5%%
Moxie  13   Aimed Weapon Bonus .. +10%%
Chutzpah .. 8   Comprehension Bonus .. +4%%
Mechanical Aptitude .. 14   Believability Bonus .. +5%%
Power Index .. 10   Repair Bonus . +5%%
===
Credits: 160Secret Society: IlluminatiSecret Society Rank: 1
Service Group: Power Services   Mutant Power: Precognition
Weapon: laser pistol to hit, 40%% type, L Range, 50m Reload, 6r Malfnt, 00
Skills: Basics 1(20%%), Aimed Weapon Combat 2(35%%), Laser 3(40%%),
   Personal Development 1(20%%), Communications 2(29%%), 
Intimidation 3(34%%)
Equipment: Red Reflec Armour, Laser Pistol, Laser Barrel (red),
  Notebook & Stylus, Knife, Com Unit 1, Jump suit,
  Secret Illuminati Eye-In-The-Pyramid(tm) Decoder ring,
  Utility Belt & Pouches
===
""" % clone

def page1():
  global page
  print """You wake up face down on the red and pink checked E-Z-Kleen 
linoleum floor.
You recognise the pattern, it's the type preferred in the internal security
briefing cells.  When you finally look around you, you see that you are alone
in a large mission briefing room.
"""
  page = 57
  more()

def page2():
  global page
  global computer_request
  print """\"Greetings,\" says the kindly Internal Security self 
incrimination expert who
meets you at the door, \"How are we doing today?\"  He offers you a doughnut
and coffee and asks what brings you here.  This doesn\'t seem so bad, so you
tell him th

BayPIGgies: January 13, 7:30pm

2005-01-10 Thread aahzpy
WARNING: the last meeting of BayPIGgies at Stanford is currently
scheduled for March.  Our host, Danny Yoo, is leaving Stanford, and we
need to find a new location.  If you wish to assist with the search,
please join the BayPIGgies mailing list.

Meanwhile, let's all give hearty thanks to Danny for helping us find a
stable meeting location for so long!


The next meeting of BayPIGgies will be Thurs, January 13 at 7:30pm.  

Danny Yoo leads a discussion of Python coding tricks and techniques.
Please join the BayPIGgies mailing list to discuss which sample code
will be demonstrated.  The web site will contain more details.

BayPIGgies meetings are in Stanford, California.  For more information
and directions, see http://www.baypiggies.net/


Before the meeting, we may meet at 6pm for dinner in downtown Palo Alto.
Discussion of dinner plans is handled on the BayPIGgies mailing list.


Advance notice: The February 10 meeting agenda has not been set.  Please
send e-mail to [EMAIL PROTECTED] if you want to make a
presentation.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Bug in Python 2.4 raw_input(u'xyz') Win/command line?

2005-01-10 Thread Petr Prikryl
Hi,

Could you test the following example for your
non-English language with accented characters?

I have observed a problem when running 
Python 2.4, Windows version (python-2.4.msi)
and using raw_input() with unicode prompt
string in a console program (ran in the DOS window).

I do use the following sitecustomize file to set
the default encoding:

sitecustomize.py
=
import sys
sys.setdefaultencoding('cp1250')
=


test.py
=
# -*- coding: cp1250 -*-
s = u'string with accented letters'
print s # OK
val = raw_input(s)# s displayed differently (wrong)
=

... when run in a DOS window. See the attached
test.png. The "type test.py" displays the string
definition also wrong, because the DOS window
uses different encoding than cp1250. The print
command prints the string correctly, converting
the internal unicode string to the encoding that
the is defined by the output environment. However,
the raw_input() probably does convert the unicode
string to the cp1250 and does not do the same
(more clever) thing that the print does.

Could you confirm the bug? Is it known?
Should this be posted into some bug-report list?

Petr


python test.py

I have observed t

-- 
Petr Prikryl (prikrylp at skil dot cz) 


test.py
Description: test.py
<>-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Getting rid of "self."

2005-01-10 Thread Alex Martelli
BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
   ...
> > http://starship.python.net/crew/mwh/hacks/selfless.py
> 
> That's excellent! There is one small problem with the code though:

It shows the fundamentals of how to rewrite the bytecode, yes.

> .class Hi(Selfless):
> .__attrs__ = ["x"]
> .def __init__(x):
> .self.x = x
> 
> In this case, I think the Python interpreter should realise that the
> parameter x shadows the attribute x. But the selfless code has
> problems with that. I want it to work exactly like how the situation
> is handled in Java and C++.

I believe you're referring to the test in rewrite_method:

if op.arg < code.co_argcount:
raise ValueError, "parameter also instance member!"

If you think that parameters that are also instance members should
"shadow" instance members, just skip the op.arg cases which are less
than code.co_argcount -- those are the parameters.

> > Alex Martelli:
> > A decorator can entirely rewrite the bytecode (and more) of the method
> > it's munging, so it can do essentially anything that is doable on the
> > basis of information available at the time the decorator executes.
> 
> Which I believe means that the instance variables have to be declared
> in the class? I am content with declaring them like the selfless
> approach does:

It means the information about which names are names of instance
attributes must be available somewhere, be that "declared", "inferred",
or whatever.  For example, many C++ shops have an ironclad rule that
instance attributes, and ONLY instance attributes, are always and
invariably named m_.  If that's the rule you want to enforce,
then you don't necessarily need other declarations or inferences, but
rather can choose to infer the status of a name from looking at the name
itself, if you wish.  "Declarations" or other complications yet such as:

> alternative would be not to declare the variables in an __attr__ list,
> and instead let them be "declared" by having them initialised in the
> __init__. I.e:
> 
> .def __init__(hi, foo):
> .self.hi = hi
> .self.foo = foo
> 
> When the metaclass then does it magic, it would go through the code of
> the __init__ method, see the assignments to "self.hi" and "self.foo",
> decide that "hi" and "foo" are attributes of the object and replace
> "hi" and "foo" in all other methods with "self.hi" and "self.foo". The

OK, but this approach is not compatible with your stated desire, which I
re-quote...:

> I want it to work exactly like how the situation
> is handled in Java and C++.

...because for example it does not deal with any attributes which may be
initialized in a *superclass*'s __init__.  However, I guess it could be
extended at the cost of some further lack of transparency, to obtain
just as horrid a mess as you require, where it's impossible for any
human reader to guess whether, say,
hi = 33
is setting a local variable, or an instance variable, without chasing
down and studying the sources of an unbounded number of superclasses.

I do not think there is any _good_ solution (which is why many C++ shops
have that rule about spelling this m_hi if it's an instance variable,
keeping the spelling 'hi' for non-instance variables -- an attempt to
get SOME human readability back; a smaller but non-null number of such
shops even achieve the same purpose by mandating the use of 'this->hi'
-- just the Python rule you want to work around, essentially).  The
least bad might be to rely on __attrs__, enriching whatever is in the
current class's __attr__ with any __attrs__ that may be found in base
classes PLUS any member variables specifically set in __init__ -- if you
focus on convenience in writing the code, to the detriment of ability to
read and understand it; or else, for more readability, demand that
__attrs__ list everything (including explicitly attributes coming from
subclasses and ones set in any method by explicit "self.whatever = ...")
and diagnose the problem, with at least a warning, if it doesn't.

Yes, there's redundancy in the second choice, but that's what
declarations are all about: if you want to introduce the equivalent of
declarations, don't be surprised if redundancy comes with them.

> downside is that it probably could never be foolproof against code
> like this:
> 
> .def __init__(hi, foo):
> .if hi:
> .self.hi = hi
> .else:
> .self.foo = foo
> 
> But AFAIK, that example is a corner case and you shouldn't write such
> code anyway. :)

I don't see any problem with this code.  A static analysis will show
that both hi and foo are local variables.  Either may be not
initialized, of course, but having to deal with variables which are not
initialized IS a common problem of C++: you said you want to do things
like in C++, so you should be happy to have this problem, too.


> > Alex Martelli:
> > You do, however, need to nail down the specs.  What your 'magic' does
> > is roughly the equivalent of a "from ... import *" (except it
> > ...

Re: Python serial data aquisition

2005-01-10 Thread Flavio codeco coelho
[EMAIL PROTECTED] (Michael Fuhr) wrote in message news:<[EMAIL PROTECTED]>...
> If the actual byte and/or bit order is different then you'll have
> to modify the expression, but this should at least give you ideas.

Thanks Michael and Steve,

I'll put your Ideas to the test ASAP, meanwhile, could you point me to
references to these bit operations in Python? I am new to this stuff,
and might need to do more of this to support other hardware...

I havent been able to find anything about this on the python
documentation..

Thanks a lot!!

Flavio
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Long strings as function parameters

2005-01-10 Thread Nick Coghlan
Jeremy Bowers wrote:
I had thought there was an obvious class in the standard library to assist
with this, but I must have been wrong.
buffer is the closest current contender, but I believe it's on the outer due to 
some problems with its implementation.

I think the intention is to eventually have a 'bytes' type, but I don't recall 
if that was going to be mutable or immutable.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


RE: interpreter Py_Initialize/Py_Finalize mem leak?

2005-01-10 Thread Roman Suzi
On Mon, 10 Jan 2005, Delaney, Timothy C (Timothy) wrote:

>Roman Suzi wrote:
>
>> In pure curiosity I tried to compile loop.c from Demo/embed
>> and started it with 'print 2+2'. It seems, that both 2.3 and 2.4
>> pythons have memory leaks in Py_Initialize/Py_Finalize calls.
>> (That is, interpreter doesn't clean up well after itself).
>
>What's your evidence for this (i.e. what are the symptoms)?

- memory usage grows over time.

>If you have a repeatable test case, please raise a bug report on
>SourceForge.

I tested only under Linux. And it is 100% repeatable.

>Tim Delaney
>

Sincerely yours, Roman Suzi
-- 
[EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: static compiled python modules

2005-01-10 Thread Nick Coghlan
Thomas Linden wrote:
How can I tell python to use the compiled in modules and not try to
load them from outside?
http://www.python.org/dev/doc/devel/api/importing.html
Take a look at the last three entries about registering builtin modules.
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python serial data aquisition

2005-01-10 Thread Paul Rubin
[EMAIL PROTECTED] (Flavio codeco coelho) writes:
> I'll put your Ideas to the test ASAP, meanwhile, could you point me to
> references to these bit operations in Python? I am new to this stuff,
> and might need to do more of this to support other hardware...
> 
> I havent been able to find anything about this on the python
> documentation..

ord(ch) turns a character into an integer, i.e. ord('a') = 97, etc.

You can use the << (left shift), >> (right shift), | (logical or),
and & (logical and) operations just like in C.

So for your diagram

 |-bits(1-8)---|
Byte1: x  x   x   n1 n2 n3   n4   n5
Byte2: x  n6 n7 n8 n9 n10 n11 n12

assuming n1 is the high order bit, you'd just say 

   value = ((ord(byte1) & 0x1f) << 7) | (ord(byte2) & 0x3f)

or something like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: accessing the result of 'if'

2005-01-10 Thread Nick Coghlan
Steve Holden wrote:
Excuse me, these are supposed to be IMPROVEMENTS to Python?
I think it's more messing around before coming to the conclusion that, of the 
many things that 'where' helps with, this sure as hell ain't one of them :)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-10 Thread Michael Sparks
Roose wrote:
...
>  I was thinking that there would be a Lisp interpreter in a kernel,
> which afaik doesn't exist.

There's an implementation of scheme that runs as a kernel module in
Linux - it's designed to allow people to experiment with exploring
kernel data structures at run time, and other fun things.

It's a case in point for avoiding saying that something that doesn't
necessarily sound sensible doesn't exist - there's a good chance it
does :)


Michael
-- 
[EMAIL PROTECTED]
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This message (and any attachments) may contain personal views
which are not the views of the BBC unless specifically stated.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: windows mem leak

2005-01-10 Thread Nick Craig-Wood
Bob Smith <[EMAIL PROTECTED]> wrote:
>  Attached is the code. Run it yourself and see.

This seems to run nmap over series of consecutive IP addresses.  nmap
can do that all by itself.  From its man page::

   Nmap also has a more powerful notation which lets  you  specify  an  IP
   address  using  lists/ranges  for  each element.  Thus you can scan the
   whole class 'B' network  128.210.*.*  by  specifying  '128.210.*.*'  or
   '128.210.0-255.0-255' or even '128.210.1-50,51-255.1,2,3,4,5-255'.  And
   of course you can use the mask notation: '128.210.0.0/16'.   These  are
   all  equivalent.  If you use astericts ('*'), remember that most shells
   require you to escape them with  back  slashes  or  protect  them  with
   quotes.

This setting might be useful too::

   --max_parallelism 
  Specifies the maximum number of scans Nmap is allowed to perform
  in parallel.  Setting this to one means Nmap will never  try  to
  scan more than 1 port at a time.  It also effects other parallel
  scans such as ping sweep, RPC scan, etc.

[sorry not Python related but may solve your problem!]
-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python serial data aquisition

2005-01-10 Thread Steve Holden
Flavio codeco coelho wrote:
[EMAIL PROTECTED] (Michael Fuhr) wrote in message news:<[EMAIL PROTECTED]>...
If the actual byte and/or bit order is different then you'll have
to modify the expression, but this should at least give you ideas.

Thanks Michael and Steve,
I'll put your Ideas to the test ASAP, meanwhile, could you point me to
references to these bit operations in Python? I am new to this stuff,
and might need to do more of this to support other hardware...
I havent been able to find anything about this on the python
documentation..
Thanks a lot!!
Flavio
ord() is documented in section 2.1 of the library reference manual 
(Built-in Functions) - see 
http://docs.python.org/lib/built-in-funcs.html#l2h-53 for further 
information.

Bitstring operations are at 
http://docs.python.org/lib/bitstring-ops.html#l2h-150

Hope this helps.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: 20050119: quoting strings

2005-01-10 Thread Steve Holden
Xah Lee wrote:
#strings are enclosed in double quotes quotes. e.g.
a="this and that"
print a
#multiple lines must have an escape backslash at the end:
b="this\n\
and that"
print b
#One can use r"" for raw string.
c=r"this\n\
and that"
print c
#To avoid the backslash escape, one can use triple double quotes to
print as it is:
d="""this
and
that"""
print d
---
# in Perl, strings in double quotes acts as Python's triple """.
# String is single quote is like Python's raw r"".
# Alternatively, they can be done as qq() or q() respectively,
#and the bracket can be just about any character,
# matching or not. (so that escapes can be easy avoided)
$a=q(here, everthing is literal, $what or \n or what not.);
$b=qq[this is
what ever including variables $a that will be
evaluated, and "quotes" needn't be quoted.];
print "$a\n$b";
#to see more about perl strings, do on shell prompt
#perldoc -tf qq
Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html
Well, that gets that sorted out, then.
Tomorrow: using single quotes. Using single quotes. The larch.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: tuples vs lists

2005-01-10 Thread Gerrit
Steve Holden wrote:
> worzel wrote:
> >'Two-Pull' it is then, thanks.
> >
> Well, it might be "Two-Pull" in American, but in English it's "tyoopl" 
> -- NOT "choopl" (blearch!). I've also heard people say "tuppl".
> 
> So, basically, say whatever you want. Language is about communication :-)

Or just write it down and don't say the word at all (-:

regards,
Gerrit, who actually says tÃpel.

-- 
Weather in Lulea / Kallax, Sweden 10/01 10:20:
-12.0ÂC   wind 0.0 m/s None (34 m above NAP)
-- 
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
-Dwight David Eisenhower, January 17, 1961
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Datetime module

2005-01-10 Thread [EMAIL PROTECTED]
take a look at the logging module as well, in the documentation
(paragraph 6.29.2 for release 2.4) you find a basic example

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Nick Coghlan
Andrey Tatarinov wrote:
And about examples for usage "where" keyword
reading http://manatee.mojam.com/~skip/python/fastpython.html I 
understand that almost every example should use that keyword =)
I suspect polluting the outer namespace would still be faster, since Python 
wouldn't have to create the extra level of scoping all the time.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Carl Banks

Paul Rubin wrote:
> "Carl Banks" <[EMAIL PROTECTED]> writes:
> > And a suite, be it a def statement, a where block, or whatever,
belongs
> > in a statement, not an expression.
>
> So do you approve of the movement to get rid of the print statement?

Any little incremental change in Python you could make by having or not
having a print statement would be minor compared to the H-Bomb of
ugliness we'd get if suites of statements were to be allowed inside
Python expressions.  Having or not having a print statement might
violate some small aspect of the Zen, but it won't rape the whole list.

So I don't know what point you're trying to make.

But to answer your question, I would prefer a Python without a print
statement, since a print method could do anything the print statement
could.


-- 
CARL BANKS

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Paul Rubin
"Carl Banks" <[EMAIL PROTECTED]> writes:
> > So do you approve of the movement to get rid of the print statement?
> 
> Any little incremental change in Python you could make by having or not
> having a print statement would be minor compared to the H-Bomb of
> ugliness we'd get if suites of statements were to be allowed inside
> Python expressions.  Having or not having a print statement might
> violate some small aspect of the Zen, but it won't rape the whole list.

How about macros?  Some pretty horrible things have been done in C
programs with the C preprocessor.  But there's a movememnt afloat to
add hygienic macros to Python.  Got any thoughts about that?

> So I don't know what point you're trying to make.

Why should you care whether the output of a macro is ugly or not,
if no human is ever going to look at it?  

> But to answer your question, I would prefer a Python without a print
> statement, since a print method could do anything the print statement
> could.

A print -method-?!!  You /really/ want to say

  your_name  = "Carl"
  your_favorite_cereal = "cornflakes"
  ("Hi", your_name, "how about a nice bowl of", your_favorite_cereal).print()

instead of 

  your_name  = "Carl"
  your_favorite_cereal = "cornflakes"
  print "Hi", your_name, "how about a nice bowl of", your_favorite_cereal



I've heard of people wanting to replace print with a function, but
hadn't heard of replacing it with a method.  Are you trying to turn
Python into Ruby?
-- 
http://mail.python.org/mailman/listinfo/python-list


Port blocking

2005-01-10 Thread Mark Carter
Supposing I decide to write a server-side application using something 
like corba or pyro.

What's the chance that in big corporations, the client's ports (in both 
 senses of the word: fee-paying, and application) will be blocked, 
thereby immediately scuppering whatever I have written? Has this problem 
ever arisen for anyone?

Also, is there a good tool for writing database UIs?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Paul Rubin
Mark Carter <[EMAIL PROTECTED]> writes:
> Supposing I decide to write a server-side application using something
> like corba or pyro.
> 
> What's the chance that in big corporations, the client's ports (in
> both senses of the word: fee-paying, and application) will be blocked,
> thereby immediately scuppering whatever I have written? Has this
> problem ever arisen for anyone?

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.

> Also, is there a good tool for writing database UIs?

Yes, quite a few.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-10 Thread Nick Coghlan
Duncan Booth wrote:
Nick Coghlan wrote:

Grammar Change
--
Current::
  statement ::=stmt_list NEWLINE | compound_stmt
New::
  statement ::=(stmt_list NEWLINE | compound_stmt) [local_namespace]
  local_namespace ::= "with" ":" suite
Semantics
-
The code::
 with:
   
translates to::
def unique_name():


unique_name()

Your proposed grammar change says that you need a newline after the 
statement:
True, and not really what I intended. However, it does highlight the fact that 
statement lists haven't been considered in the discussion so far.

If statement lists are permitted, getting the right targets bound in the 
containing scope is going to be fun for things like this:

a = b = 2; c = 3; print a + b with:
  pass
(Probably not impossible though - e.g. it may be feasible to figure out all the 
bindings that have to happen and return an appropriate tuple from the inner 
scope for binding in the outer scope)

It might also be somewhat confusing as to exactly which statements are covered 
by the local scoping. (All of them would be, but you could be forgiven for 
assuming it was just the last one)

I think the following would work as a version of the grammar which permits local 
namespaces for statement lists:

  statement ::= (stmt_list (NEWLINE | local_namespace)) |
(compound_stmt [local_namespace])
  local_namespace ::= "with" ":" suite
Disallowing local namespaces for statement lists would suggest something like 
this:
  statement ::= (simple_stmt
  (NEWLINE | ";" stmt_list NEWLINE | local_namespace)
 ) |
(compound_stmt [local_namespace])
  local_namespace ::= "with" ":" suite
I'm pretty sure the permissive version is legal for the CPython parser, and I 
think the somewhat baroque structure I've used for the restrictive version makes 
it legal, too.

Disallowing local namespaces for statement lists might be a good place to start, 
since it gives an easier target for a first implementation.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Carl Banks

Paul Rubin wrote:
> "Carl Banks" <[EMAIL PROTECTED]> writes:
> > > So do you approve of the movement to get rid of the print
statement?
> >
> > Any little incremental change in Python you could make by having or
not
> > having a print statement would be minor compared to the H-Bomb of
> > ugliness we'd get if suites of statements were to be allowed inside
> > Python expressions.  Having or not having a print statement might
> > violate some small aspect of the Zen, but it won't rape the whole
list.
>
> How about macros?  Some pretty horrible things have been done in C
> programs with the C preprocessor.  But there's a movememnt afloat to
> add hygienic macros to Python.  Got any thoughts about that?

How about this: Why don't you go to a Python prompt, type "import
this", and read the Zen of Python.  Consider each line, and whether
adding macros to the language would be going against that line or for
it.  After you've done that, make an educated guess of what you think
I'd think about macros, citing various Zens to support your guess.

Then I'll tell you what my my thoughts about it are.


> > So I don't know what point you're trying to make.
>
> Why should you care whether the output of a macro is ugly or not,
> if no human is ever going to look at it?

I don't.


> > But to answer your question, I would prefer a Python without a
print
> > statement, since a print method could do anything the print
statement
> > could.
>
> A print -method-?!!
[snip example]
>
> I've heard of people wanting to replace print with a function, but
> hadn't heard of replacing it with a method.  Are you trying to turn
> Python into Ruby?

I'll give you the benefit of the doubt that you just didn't think it
over thoroughly.  I was thinkging would be a method of file like
objects.

stdout.print("hello")


-- 
CARL BANKS

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Mark Carter
Paul Rubin wrote:
Mark Carter <[EMAIL PROTECTED]> writes:
Supposing I decide to write a server-side application using something
like corba or pyro.

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.
Although, when you think about it, it kinda defeats the purposes of 
firewalls. Not that I'm criticising you personally, you understand.

Also, is there a good tool for writing database UIs?

Yes, quite a few.
Ah yes, but is there really? For example, I did a search of the TOC of 
GTK+ Reference Manual:
http://developer.gnome.org/doc/API/2.0/gtk/index.html
for the word "data", and there's apparently no widget which is 
explicitly tied to databases. So in GTKs case, for instance, it looks 
like one has to roll one's own solution, rather than just using one out 
of the box.
--
http://mail.python.org/mailman/listinfo/python-list


Command line and GUI tools : need a single threading solution

2005-01-10 Thread Adrian Casey
I have a collection of multi-threaded command line tools which I want wrap a
PyQt gui around.  I'm using queues to route messages from the command line
tools to the PyQt gui. The command line tools use python threads to do
their work.  The gui uses a QThread object to read incoming messages.

This does not work consistently - and I've since read that mixing python
threads and QThreads is a bad idea.  The command line tools work well using
python threads.

I don't want to maintain two copies of the tools - one for command line and
another for the PyQt version.

I'm thinking it may be possible to modify the command line tools to use qt
threads instead of native python threads.  Is this the way to go?  Are
there other options?

Adrian.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Command line and GUI tools : need a single threading solution

2005-01-10 Thread Diez B. Roggisch
> I'm thinking it may be possible to modify the command line tools to use qt
> threads instead of native python threads.  Is this the way to go?  Are
> there other options?

Why don't you use python threads in qt - I do so and so far it didn't make
any troubles for me. And I would strongly advise against using qthreads
with your commandline-tools, as these then would only run on machines where
pyqt is installed - which opens a small part of "dependency hell" for your
users.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Diez B. Roggisch
> Usually you wouldn't run a public corba or pyro service over the
> internet.  You'd use something like XMLRPC over HTTP port 80 partly
> for the precise purpose of not getting blocked by firewalls.

What exactly makes sending bytes over port 80 more secure than over any
other port? It has always been my impression that this was to create less
administrative troubles for firewall admins.  But its not inherently more
secure. That's a property of the application running.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Command line and GUI tools : need a single threading solution

2005-01-10 Thread Phil Thompson
> I have a collection of multi-threaded command line tools which I want wrap
> a
> PyQt gui around.  I'm using queues to route messages from the command line
> tools to the PyQt gui. The command line tools use python threads to do
> their work.  The gui uses a QThread object to read incoming messages.
>
> This does not work consistently - and I've since read that mixing python
> threads and QThreads is a bad idea.  The command line tools work well
> using
> python threads.

How well mixing the two threading APIs works depends on version numbers. A
PyQt generated with SIP v4.x (rather than SIP v3.x) with Python v2.4
should be Ok.

> I don't want to maintain two copies of the tools - one for command line
> and
> another for the PyQt version.
>
> I'm thinking it may be possible to modify the command line tools to use qt
> threads instead of native python threads.  Is this the way to go?  Are
> there other options?

Using QThreads only should work - just tell the QApplication ctor that you
have a console application.

Phil

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Datetime module

2005-01-10 Thread Mark McEahern
[EMAIL PROTECTED] wrote:
I am writing a script that acts as an AIM bot [using twisted.IM's base
scripts] and I want to add a logging feature. I got it to log who sends
what to whom, but what I want to add is the date and time that the
message was sent (or recieved by the bot), I tried to look at datetime
on my own, and I couldn't get anything to work.
Anyone know a simple way to get the current date and/or time?
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2005, 1, 10, 6, 39, 56, 64000)
>>> print datetime.datetime.now()
2005-01-10 06:40:03.705000
>>>
You may also want to consider using the logging module.
// m
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Paul Rubin
"Carl Banks" <[EMAIL PROTECTED]> writes:

> Paul Rubin wrote:
> > "Carl Banks" <[EMAIL PROTECTED]> writes:
> > > > So do you approve of the movement to get rid of the print
> statement?
> > >
> > > Any little incremental change in Python you could make by having or
> not
> > > having a print statement would be minor compared to the H-Bomb of
> > > ugliness we'd get if suites of statements were to be allowed inside
> > > Python expressions.  Having or not having a print statement might
> > > violate some small aspect of the Zen, but it won't rape the whole
> list.
> >
> > How about macros?  Some pretty horrible things have been done in C
> > programs with the C preprocessor.  But there's a movememnt afloat to
> > add hygienic macros to Python.  Got any thoughts about that?
> 
> How about this: Why don't you go to a Python prompt, type "import
> this", and read the Zen of Python.  Consider each line, and whether
> adding macros to the language would be going against that line or for
> it.  After you've done that, make an educated guess of what you think
> I'd think about macros, citing various Zens to support your guess.
> 
> Then I'll tell you what my my thoughts about it are.


The Zen of Python, by Tim Peters

Beautiful is better than ugly.   => +1 macros 
Explicit is better than implicit. => +1 macros
Simple is better than complex.  => +1 macros
Complex is better than complicated.  => I don't understand this, +0
Flat is better than nested.  => not sure, +0
Sparse is better than dense. => +1 macros
Readability counts. => +1 macros
Special cases aren't special enough to break the rules. => +1 macros
Although practicality beats purity. => +1 macros
Errors should never pass silently. => +1 macros
Unless explicitly silenced. => +1 macros
In the face of ambiguity, refuse the temptation to guess. => +1 macros
There should be one-- and preferably only one --obvious way to do it. => -1
Although that way may not be obvious at first unless you're Dutch. => ???
Now is better than never. => +1 macros, let's do it
Although never is often better than *right* now. => +1 
If the implementation is hard to explain, it's a bad idea. => unknown, +0
If the implementation is easy to explain, it may be a good idea. => +0
Namespaces are one honking great idea -- let's do more of those! => +1

I'm -1 on doing stuff by received dogma, but in this particular case
it looks to me like the dogma is +12 for macros.  What are your thoughts?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Anna

Jacek Generowicz wrote:
> "Anna" <[EMAIL PROTECTED]> writes:
>
> > With class and def, I at least have a *name* to start with - class
> > Square pretty obviously is going to have something to do with
> > geometric shapes, I would hope (or maybe with boring people...).
>
> Or maybe with multiplying something by itself. Or maybe the author
> made some changes in his program, and forgot to rename the class
> sensibly, and the class' functionality has nothing to do with squares
> of any sort any more. Or maybe he felt the name "Square" was very
> appropriate for something else in his program and inadvertently gave
> the same name to two different entities thereby clobbering the one
> whose use was intended at this point.

Idjits abound. ;-)

Can't make anything foolproof because fools are so ingenious.

> > Whereas, with lambda - I have *nothing* to go on.
>
> Aaah. OK, you object to lambda because it gives you no clue as to
what
> the function does, rather than with the word "lambda" itself? Is that
> it?
>
> So, IIUC, you consider
>
>def add_one(x):
>return x+1
>
>map(add_one, seq)
>
> to be clearer than
>
>map(lambda x:x+1, seq)

Completely, totally, and unambiguously: the version with the defined
function is immediately clear to me; the version with the lambda is
decipherable, but requires deciphering (even at 2nd and 3rd glance).
But first, wouldn't something like:

[x+1 for x in seq]

be even clearer?

Given an example more complex (which you must admit, lambdas usually
are) - the name of the function is something my brain can hold on to to
represent the group of operations; where with the lambda, I need to
mentally go through each operation each time I try to read it. And the
more complex f is, the harder time I have holding it all in my head
while I figure out how to get from the beginning value x to the ending
value f(x). lambda is an O(N*N) problem for my brain.

I could see someone more mathematically-minded being happier with
lambda. It's not, after all, the word "lambda" itself; I would still
have some issues with using, say "function", instead of "lambda", but
at least then I would immediately know what I was looking at...

Anna

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-10 Thread Nick Coghlan
Nick Coghlan wrote:
Disallowing local namespaces for statement lists would suggest something 
like this:

  statement ::= (simple_stmt
  (NEWLINE | ";" stmt_list NEWLINE | local_namespace)
 ) |
(compound_stmt [local_namespace])
  local_namespace ::= "with" ":" suite
Corrected version of the above to avoid an unintended syntax change:
  statement ::= (simple_stmt
  (NEWLINE | ";" [stmt_list] NEWLINE | local_namespace)
 ) |
(compound_stmt [local_namespace])
  local_namespace ::= "with" ":" suite
(The original version incorrectly prohibited a trailing semi-colon for a single 
statement)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Old Paranoia Game in Python

2005-01-10 Thread Lucas Raab
[EMAIL PROTECTED] wrote:
Aahz wrote:
Trust the computer, the computer is your friend.

However, the computer isn't a fuckin' mind reader.
If you're going to post source code on the usenet, don't
have lines longer than 72 characters. Otherwise you'll
find your code has wrapped lines. This not only causes
syntax errors in your choose and print statements but
also fucks up the formatting of of printed paragraphs.
Stupid human.
Temper, temper...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Mark Carter
Mark Carter wrote:
Paul Rubin wrote:

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.
I'm not sure if we're talking at cross-purposes here, but the 
application isn't intended for public consumption, but for fee-paying 
clients.
--
http://mail.python.org/mailman/listinfo/python-list


Re: windows mem leak

2005-01-10 Thread Nick Coghlan
Bob Smith wrote:
Peter Hansen wrote:
Bob Smith wrote:
Attached is the code. Run it yourself and see. You too Peter. Be 
gentle with me, this was my first attempt with threads.

Thanks, Bob, and I will, but not before you answer some of my
questions.
I had good reasons to ask them, one of which is that I don't
feel like wasting my time if, for example, you are using an
older version of Python that *did* have a memory leak.

2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)]
Perhaps you could try using the new subprocess module, instead of using os.popen 
directly.

A fair amount of work went into making the Windows implementation of that module 
as solid as the *nix implementation, whereas there may still be issues with 
direct os.popen calls (as Roel's investigation suggests).

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: tuples vs lists

2005-01-10 Thread Antoon Pardon
Op 2005-01-08, Bruno Desthuilliers schreef <[EMAIL PROTECTED]>:
> worzel a écrit :
>> I get what the difference is between a tuple and a list, but why would I 
>> ever care about the tuple's immuutability?
>
> Because, from a purely pratical POV, only an immutable object can be 
> used as kay in a dict.

This is not true.

> So you can use tuples for 'composed key'.

lists can be so used too. Just provide a hash.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Powerful CGI libraries for Python?

2005-01-10 Thread Thomas Guettler
Am Mon, 10 Jan 2005 10:11:16 +0800 schrieb sam:

> Hi,
> 
> I m looking for a CGI libraries just  like perl's CGI.pm for Python.
>  From google, I found quite a few of CGI libraries already written for 
> python. But I haven't had experience to try any of them in Python.
> 
> Can anyone share your Python CGI experience with me? Which library is 
> better in terms of functionality and stability?

Hi,

in the standard library there is cgi and cgitb. If you just want to
write a small cgi script, both modules should be all you need.

I found quixote simple and easy to learn. Quixote 1.x is quite stable.
The version I use is more then six months old, and there is no need to
update.

Take a look at:
http://www.python.org/cgi-bin/moinmoin/WebProgramming

 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-10 Thread Nick Coghlan
Terry Reedy wrote:
"Andrey Tatarinov" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

How does GvR suggestions on removing map(), reduce(), filter()

While GvR *might* prefer removing them completely on any given day, I think 
moving them to a functional module, as others have suggested and requested, 
is currently more likely.  I believe that GvR has indicated at times that 
this would be an acceptible compromise.

I am one of those who think the list of builtins is currently too long to 
be easily grasped and should be shrunk.
Heh. When PEP 309 hits CVS (with functional.partial), maybe it can grow aliases 
for the three of them so people can get used to the idea.

It might keep partial from getting too lonely. . . :)
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


C structure in the Python extension

2005-01-10 Thread Dave win
Howdy:
When I was writting interface functions of the extending python,  I
meet a question. As I using the  "PyArg_ParseTuple(args,arg_type,...)"
function call, if I wanna use the personal defined argument, such as the
C structure which I made. How to make it?

static PyObject* Call_V_ABSUB(PyObject *self, PyObject* args){
  myStruct FU;
  myStruct result;
  if(!PyArg_ParseTuple(args,"O&",&FU)) return NULL;
 ^^^
 How to modify here???
  V_ABSUB(FU);

  return Py_BuildValue("i",result);
}




Thx.

Dave.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed revisited

2005-01-10 Thread Nick Coghlan
John Machin wrote:
My wild guess: Not a common use case. Double-ended queue is a special
purpose structure.
As Kent said, the suggestion of making index 0 insertions and deletions on lists 
more efficent was made, and the decision was to leave list alone and provide 
collections.deque instead. This let deque sacrifice some of list's flexibility 
in favour of increased speed.

Appropriate parts of the core which needed a FIFO were then updated to use the 
new data type, while everything else continues to use lists.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Jonas Galvez
Andrey Tatarinov wrote:
> It would be great to be able to reverse usage/definition parts 
> in haskell-way with "where" keyword.

Hi folks, I really like this idea. But I couldn't help but think 
of a few alternative ways. I'm no language design expert by any 
means, but I'm a little concerned with the idea of an 'expression' 
preceding a 'block'. Maybe I'm naive (actually, I'm pretty sure I 
am), but I think a decorator-like syntax would be a little more 
Pythonic. Here's a small example:

def where(closure=None, *v):
if not False in v:
closure(*v)

def foo(a, b):
@where(a: int, b: int):
return str(a) + str(b)
raise TypeMismatch

The (variable : type) could be turned into a syntact sugar for 
(type(variable) is type). Basically, this would be a simple 
implementation of the so called "closures", where a decorator is 
able to 'receive' a code block, which would be passed as a 
function as the first argument of the decorator. (Is this clear?)

As I said, I'm no language design expert and I'm sure I'm breaking 
a few important rules here heh. But I find it cool. This is not a 
proposal. I'm just thinking out loud :)


Jonas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Grant Edwards
On 2005-01-10, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

>> Usually you wouldn't run a public corba or pyro service over
>> the internet.  You'd use something like XMLRPC over HTTP port
>> 80 partly for the precise purpose of not getting blocked by
>> firewalls.
>
> What exactly makes sending bytes over port 80 more secure than
> over any other port?

Nothing.

When has reality had anything to do with the way corporate IT
types configure firewalls?  ;)

> It has always been my impression that this was to create less
> administrative troubles for firewall admins.

It's to give corporate IT types the _illusion_ of security and
relieve them of the need to learn how to configure firewalls.

> But its not inherently more secure. That's a property of the
> application running.

-- 
Grant Edwards   grante Yow!  HAIR TONICS, please!!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Ville Vainio
> "James" == James Stroud <[EMAIL PROTECTED]> writes:

James> I think we should not try too hard to make everything
James> "English" like. Its a crappy language anyway (though its
James> the only one I speak good). Matt Neuberg,

QOTW material, unless you stole this from someone else :-).

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: google groups bug, or worse?

2005-01-10 Thread Tomi Häsä
[EMAIL PROTECTED] wrote:
> I'm concerned that google groups is not correctly reflecting
> the python lists.
> [...]
> Is it a google bug?

Yes, Google Groups Beta is missing messages:

http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/c4108ad41c189d34?tvc=2
http://tinyurl.com/6vybw
http://groups-beta.google.com/group/google-labs-groups2/msg/dc745c7784c81890
http://tinyurl.com/4keqh
http://groups-beta.google.com/group/google-labs-groups2/msg/b54c12517c75eb24

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Carl Banks
Paul Rubin wrote:
>
> The Zen of Python, by Tim Peters
>
> Beautiful is better than ugly.   => +1 macros
> Explicit is better than implicit. => +1 macros
> Simple is better than complex.  => +1 macros
> Complex is better than complicated.  => I don't understand this,
+0
> Flat is better than nested.  => not sure, +0
> Sparse is better than dense. => +1 macros
> Readability counts. => +1 macros
> Special cases aren't special enough to break the rules. => +1
macros
> Although practicality beats purity. => +1 macros
> Errors should never pass silently. => +1 macros
> Unless explicitly silenced. => +1 macros
> In the face of ambiguity, refuse the temptation to guess. => +1
macros
> There should be one-- and preferably only one --obvious way to do
it. => -1
> Although that way may not be obvious at first unless you're
Dutch. => ???
> Now is better than never. => +1 macros, let's do it
> Although never is often better than *right* now. => +1
> If the implementation is hard to explain, it's a bad idea. =>
unknown, +0
> If the implementation is easy to explain, it may be a good idea.
=> +0
> Namespaces are one honking great idea -- let's do more of those!
=> +1
>
> I'm -1 on doing stuff by received dogma, but in this particular case
> it looks to me like the dogma is +12 for macros.  What are your
thoughts?

Paul,

When I asked you to do this, it was just a rhetorical way to tell you
that I didn't intend to play this game.  It's plain as day you're
trying to get me to admit something.  I'm not falling for it.

If you have a point to make, why don't you just make it?
-- 
CARL BANKS

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Ville Vainio
> "Mark" == Mark Carter <[EMAIL PROTECTED]> writes:

Mark> Mark Carter wrote:
>> Paul Rubin wrote:

>>> Usually you wouldn't run a public corba or pyro service over
>>> the internet.  You'd use something like XMLRPC over HTTP port
>>> 80 partly for the precise purpose of not getting blocked by
>>> firewalls.

Mark> I'm not sure if we're talking at cross-purposes here, but
Mark> the application isn't intended for public consumption, but
Mark> for fee-paying clients.

Still, if the consumption happens over the internet there is almost
100% chance of the communication being prevented by firewalls.

This is exactly what "web services" are for.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2005-01-10 Thread Tomi Häsä
Dan Bishop wrote:
>
> And for a long time, Google groups postings *were* whitespace
> significant.  But the new interface broke it.
>
> > I made a complaint several weeks ago to Google support,
> > asking them too quit stripping leading whitespace,
> > and the sent me a reply saying they appreciated my feedback.
> > Maybe they  just need more feedback :)
>
> I send them some earlier today.  So far, I've only received
> their auto-reply.

Removing and adding spaces discussed in the Google Groups Beta group
also:

http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/9bc4328fd27d3ad4/80ad25b58d5dbb49?_done=%2Fgroup%2Fgoogle-labs-groups2%2Fthreads%3Fstart%3D60%26order%3Drecent%26&_doneTitle=Back&&d#80ad25b58d5dbb49
http://tinyurl.com/6oe6v
http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/73b712c45c9d89d2/bdc0544e3b08a1cd?_done=%2Fgroup%2Fgoogle-labs-groups2%2Fthreads%3Fstart%3D120%26order%3Drecent%26&_doneTitle=Back&&d#bdc0544e3b08a1cd
http://tinyurl.com/5nz5u

Demonstration of the problem:

http://groups-beta.google.com/group/Groups-2-Test-Group/browse_thread/thread/cc5a64d2e18f0594/945fa09eea37e41c?_done=%2Fgroup%2FGroups-2-Test-Group%3F&_doneTitle=Back+to+topics&_doneTitle=Back&&d#945fa09eea37e41c
http://tinyurl.com/4wem9

More problems listed here:

http://groups-beta.google.com/group/google-labs-groups2/msg/b54c12517c75eb24
http://tinyurl.com/3khmj

More info in the FAQ:
http://www.geocities.com/googlepubsupgenfaq/#groupsproblems

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Paul Rubin
"Carl Banks" <[EMAIL PROTECTED]> writes:
> When I asked you to do this, it was just a rhetorical way to tell you
> that I didn't intend to play this game.  It's plain as day you're
> trying to get me to admit something.  I'm not falling for it.
> 
> If you have a point to make, why don't you just make it?

You asked me to compare the notion of macros with the Zen list.  I did
so.  I didn't see any serious conflict, and reported that finding.
Now you've changed your mind and you say you didn't really want me to
make that comparison after all.

An amazing amount of the headaches that both newbies and experienced
users have with Python, could be solved by macros.  That's why there's
been an active interest in macros for quite a while.  It's not clear
what the best way to do design them is, but their existence can have a
profound effect on how best to do these ad-hoc syntax extensions like
"where".  Arbitrary limitations that are fairly harmless without
macros become a more serious pain in the neck if we have macros.

So, we shouldn't consider these topics separately from each other.
They are likely to end up being deeply related.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a new Perl/Python a day

2005-01-10 Thread François Pinard
[Andy Gross]

> On Jan 10, 2005, at 12:11 AM, Scott Bryce wrote:

> >No. Perl may have some interesting idiosyncrasies

> I [...] still have to look at the documentation to remember that I
> need to type '$|' to turn buffering off.  Ditto for the rest of the
> perl line-noise syntax.

Behind each language, there is a culture.  The Perl man pages give many
mnemonic tricks to remember special variable names like the above, and
if you are willing to play the game the way it was written, you might
even have some fun at it, and easily be proficient at this "line-noise".

I did a lot of Perl for many years, and still appreciate what Perl is
(or at least was).  Python does not change Perl in my eyes.  However,
Python is significantly more legible and maintainable, the comparison
merely stresses the unreadability of Perl.  No doubt that I prefer
Python, but Python not being there, Perl would be quite useful to me.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (Jan 9)

2005-01-10 Thread Josiah Carlson
QOTW:  Jim Fulton: "[What's] duck typing?"
Andrew Koenig: "That's the Australian pronunciation of 'duct taping'."

"I'm thinking that the I-Ching is a vast untapped resource for programming
wisdom, plus it makes it funny." -- Mark Carter


Nick Coghlan brings up the 'lambdas are going away in 3.0' topic, which
has been discussed before:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/81e17b1d3ccba538

A user asks about a non-generator-based method for iteration using class
__iter__ and next() methods:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6336a00ad217888a

Daniel Bickett asks about getting Twisted and wxPython working together,
and receives both a threaded and non-threaded version:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/73f1e7758225afc3

A question about iterating over floats...be careful!

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1278866159ac4429

A Boogieman asks whether Python is easily learned and what can be done
with it.  Quick answer: yes, and anything you are capable of doing:
This Boogieman later asks about GUI toolkits:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/e67b776df72eb336

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/d502698b4adacd01

Erik Bethke writes Majong game after using Python for a month.  Ahh, will
the wonders of Python never cease?

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6d710e35007f0f32

Kamilche asks about getting warnings when not calling a function, and gets
pointed to pychecker, something more of us should be using:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/dff810b7dacd247c

Are people allowed to build commercial applications in Python?  YES!

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/aa953388db68b196

Questions about asyncore brings up a web server in asyncore from _Python
Web Programming_, and a pointer to Twisted.  Alternatively, one could look
at the asynchat or smtpd modules in the standard library as sources of
inspiration:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/81360ec06013e36d


Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Brett Cannon continues the marvelous tradition established by 
Andrew Kuchling and Michael Hudson of intelligently summarizing
action on the python-dev mailing list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

The Python Business Forum "further[s] the interests of companies
that base their business on ... Python."
http://www.python-in-business.org

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlin

Re: Using ICL to compile C extensions

2005-01-10 Thread John Carter
On 3 Jan 2005 21:18:13 -0800, [EMAIL PROTECTED] wrote:

>Hi,
>
>Does anyone know how I can use "icl" (Intel C++) to compile C
>extensions? I'm on Windows, and my Python is compiled using VS7.1
>(binary distribution). Right now, when I run setup.py install, it uses
>cl.exe (MSVC++ Toolkit 2003), and I would like to use icl because
>MSVC++ 2003 does not support C99.
>Any help will be much appreciated.
>
>Cheers,
>Michael

I've not tried to do it using distutils yet, but when I was building
extension modules with my own make files and nmake all I had to do was
chance cl to icl and use the correct linker. You can tune the
performance playing with switches, but I got a factor 3 improvement on
a DCT type algorithm with out of the box settings.

I can send you an example makefile if you want

John Carter

[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Developing Commercial Applications in Python

2005-01-10 Thread bit_bucket5
See http://www.journynx.com/
Commercial timesheet app written in Python.

[EMAIL PROTECTED] wrote:
> Hello All,
> I am trying to convince my client to use Python in his new product.
He
> is worried about the license issues. Can somebody there to point me
any
> good commercial applications developed using python ?. The licence
> clearly says Python can be used for commercial applications. Is there
> any other implications like that of GPL to make the source open ?
> Thanks for any help.
> eeykay

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Carl Banks
Paul Rubin wrote:
> "Carl Banks" <[EMAIL PROTECTED]> writes:
> > When I asked you to do this, it was just a rhetorical way to tell
you
> > that I didn't intend to play this game.  It's plain as day you're
> > trying to get me to admit something.  I'm not falling for it.
> >
> > If you have a point to make, why don't you just make it?
>
> You asked me to compare the notion of macros with the Zen list.  I
did
> so.  I didn't see any serious conflict, and reported that finding.
> Now you've changed your mind and you say you didn't really want me to
> make that comparison after all.

I asked you to make an educated guess about what I would think of them,
which you didn't do.  I wanted you to apply the Zen to macros so that
you could justify the guess.  I wasn't interested in your thoughts.


> An amazing amount of the headaches that both newbies and experienced
> users have with Python, could be solved by macros.  That's why
there's
> been an active interest in macros for quite a while.  It's not clear
> what the best way to do design them is, but their existence can have
a
> profound effect on how best to do these ad-hoc syntax extensions like
> "where".  Arbitrary limitations that are fairly harmless without
> macros become a more serious pain in the neck if we have macros.

What good are macros going to do when they entail (according to you)
saddling the language with all this unreadable crap?  You may say
macros are not against the Zen of Python, but for their sake, you will
add a million things that are.  Net effect is, you've taken away
everything that makes Python great.

But here's the best part: all of this is to avoid a "serious pain in
the neck."

Get real, Paul.

Here's a thought: if macros are so great, it should be pretty easy for
you to create a halfway syntax with none of these pesky so-called
"arbitrary limitations" and have macros automatically turn it into
legal Python.  Don't you think that's maybe better than turning the
language into an unreadable blob?

No, of course you don't, because an unreadable blob is the LISP way.


> So, we shouldn't consider these topics separately from each other.
> They are likely to end up being deeply related.

No, Paul, they're likely never to be related because Python is never
going to have macros.  Or, at least not the general sort that you want.
-- 
CARL BANKS

-- 
http://mail.python.org/mailman/listinfo/python-list


"Re: Re: Probleme mit der Installation der openSource Bittorrent.... python vs JAVA"

2005-01-10 Thread xunling
i still need an answer ... anyone out there who could help me plz? :/

thx - xun
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-10 Thread Anna
+1

I really like the idea of this. It removes all my objections to
lambdas, and replaces it with something clear and readable.
I look forward to seeing what comes of it.

Anna

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Powerful CGI libraries for Python?

2005-01-10 Thread Jeff Reavis
You may want to check out Spyce http://spyce.sourceforge.net/index.html

It will work as cgi (or using fast cgi or mod python) and has
templating, session support, active tags, etc.

-jjr

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-10 Thread Arich Chanachai
Arich Chanachai wrote:
Paul Rubin wrote:
"Roose" <[EMAIL PROTECTED]> writes:
   


What I really wonder about is the possibility of integrating Mono with a 
kernel and building upward (the "shell" if you will) using IronPython.
--
http://mail.python.org/mailman/listinfo/python-list


Re: else condition in list comprehension

2005-01-10 Thread Luis M. Gonzalez
It's me wrote:
> > z = [i + (2, -2)[i % 2] for i in range(10)]
>
> But then why would you want to use such feature?  Wouldn't that make
the
> code much harder to understand then simply:
>
> z=[]
> for i in range(10):
> if  i%2:
> z.append(i-2)
> else:
> z.append(i+2)
>
> Or are we trying to write a book on "Puzzles in Python"?


Once you get used to list comprehensions (and it doesn't take long),
they are a more concise and compact way to express these operations.
I think that writing 6 lines instead of 1 could be more readable of you
are a beginner, but after playing a little bit with listcomps for the
first time, you'll see they are very practical yet readable.

-- 
http://mail.python.org/mailman/listinfo/python-list


pulling info from website

2005-01-10 Thread bob
i am trying to write a script for Xbox media center that will pull
information from the bbc news website and display the headlines , how do i
pull this info into a list???


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pulling info from website

2005-01-10 Thread Duncan Booth
bob wrote:

> i am trying to write a script for Xbox media center that will pull
> information from the bbc news website and display the headlines , how
> do i pull this info into a list???
> 
> 

Google for "Python RSS reader" and read some of the results.

http://effbot.org/zone/effnews.htm probably answers many of your questions, 
especially since he uses the BBC news headlines as an example.
-- 
http://mail.python.org/mailman/listinfo/python-list


Writing huge Sets() to disk

2005-01-10 Thread Martin MOKREJŠ
Hi,
 I have sets.Set() objects having up to 20E20 items,
each is composed of up to 20 characters. Keeping
them in memory on !GB machine put's me quickly into swap.
I don't want to use dictionary approach, as I don't see a sense
to store None as a value. The items in a set are unique.
 How can I write them efficiently to disk? To be more exact,
I have 20 sets. _set1 has 1E20 keys of size 1 character.
alphabet = ('G', 'A', 'V', 'L', 'I', 'P', 'S', 'T', 'C', 'M', 'A', 'Q', 'F', 
'Y', 'W', 'K', 'R', 'H', 'D', 'E')
for aa1 in alphabet:
   # l = [aa1]
   #_set1.add(aa1)
   for aa2 in alphabet:
   # l.append(aa2)
   #_set2.add(''.join(l))
[cut]
 The reason I went for sets instead of lists is the speed,
availability of unique, common and other methods.
What would you propose as an elegant solution?
Actually, even those nested for loops take ages. :(
M.
--
http://mail.python.org/mailman/listinfo/python-list


Re: else condition in list comprehension

2005-01-10 Thread Steven Bethard
Luis M. Gonzalez wrote:
It's me wrote:
z = [i + (2, -2)[i % 2] for i in range(10)]
But then why would you want to use such feature?  Wouldn't that make
the code much harder to understand then simply:
z=[]
for i in range(10):
if  i%2:
z.append(i-2)
else:
z.append(i+2)
Or are we trying to write a book on "Puzzles in Python"?
Once you get used to list comprehensions (and it doesn't take long),
they are a more concise and compact way to express these operations.
After looking the two suggestions over a couple of times, I'm still 
undecided as to which one is more readable for me.  The problem is not 
the list comprehensions (which I love and use extensively).  The problem 
is the odd syntax that has to be used for an if/then/else expression in 
Python.  I think I would have less trouble reading something like:

z = [i + (if i % 2 then -2 else 2) for i in range(10)]
but, of course, adding a if/then/else expression to Python is unlikely 
to ever happen -- see the rejected PEP 308[1].

Steve
[1] http://www.python.org/peps/pep-0308.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread Martin MOKREJŠ
Batista, Facundo wrote:
[Martin MOKREJ?]
#-   I have sets.Set() objects having up to 20E20 items,
#- each is composed of up to 20 characters. Keeping
Are you really sure??
Either I'll have to construct them all over again say
20-30 times, or I'll find a way to keep them on disk.

#-   How can I write them efficiently to disk? To be more exact,
I think that there's some mistake here.
At least you'll need a disk of 34694 EXABYTES!!!
Hmm, you are right. So 20E15 then? I definitely need to be
in range 1-14. ;-)
Anyway they are large.
M.
--
http://mail.python.org/mailman/listinfo/python-list


RE: Writing huge Sets() to disk

2005-01-10 Thread Robert Brewer
Martin MOKREJŠ wrote:
>   I have sets.Set() objects having up to 20E20 items,
> each is composed of up to 20 characters. Keeping
> them in memory on !GB machine put's me quickly into swap.
> I don't want to use dictionary approach, as I don't see a sense
> to store None as a value. The items in a set are unique.
> 
>   How can I write them efficiently to disk?

got shelve*?


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]

* the "shelve" module in the standard library, that is.
--
http://mail.python.org/mailman/listinfo/python-list


RE: Writing huge Sets() to disk

2005-01-10 Thread Batista, Facundo
Title: RE: Writing huge Sets() to disk





[Martin MOKREJŠ]


#- > At least you'll need a disk of 34694 EXABYTES!!!
#- 
#- Hmm, you are right. So 20E15 then? I definitely need to be


Right. Now you only need 355 PETABytes. Nowadays disk is cheap, but...



#- in range 1-14. ;-)


Why?



.    Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pulling info from website

2005-01-10 Thread Rick Holbert
Bob,

Have a look at feedparser:

http://www.feedparser.org/
http://diveintomark.org/projects/feed_parser/

For bbc news feeds, I use the following url:

http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/front_page/rss091.xml

bob wrote:

> i am trying to write a script for Xbox media center that will pull
> information from the bbc news website and display the headlines , how do i
> pull this info into a list???

-- 
http://mail.python.org/mailman/listinfo/python-list


syntax error in eval()

2005-01-10 Thread harold fellermann
Hi all,
I am trying to dynamically add class attributes at runtime using the 
function eval(),
i.e. I want to do something like

>>> class X : pass
...
>>> X.attr = 5
but without knowing either the attributes name nor its value.
However, I encounter a syntax error I cannot understand:
Python 2.4 (#1, Dec 30 2004, 08:00:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class X : pass
...
>>> attrname = "attr"
>>> eval("X.%s = val" % attrname , {"X":X, "val":5})
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 1
X.attr = val
   ^
SyntaxError: invalid syntax
Does anyone have a clue what might be wrong? Thanks in advance.
- harold -
--
"I know what I believe. I will continue to articulate what I believe
 and what I believe - I believe what I believe is right."
-- George W. Bushman
--
http://mail.python.org/mailman/listinfo/python-list


Re: syntax error in eval()

2005-01-10 Thread Steven Bethard
harold fellermann wrote:
Python 2.4 (#1, Dec 30 2004, 08:00:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> class X : pass
...
 >>> attrname = "attr"
 >>> eval("X.%s = val" % attrname , {"X":X, "val":5})
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 1
X.attr = val
   ^
SyntaxError: invalid syntax
You may want to use exec instead of eval:
py> class X(object):
... pass
...
py> attrname = "attr"
py> exec "X.%s = val" % attrname in dict(X=X, val=5)
py> X.attr
5
But personally, I'd use setattr, since that's what it's for:
py> class X(object):
... pass
...
py> attrname = "attr"
py> setattr(X, attrname, 5)
py> X.attr
5
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Speed revisited

2005-01-10 Thread Bulba!
On Sun, 09 Jan 2005 22:51:47 GMT, Andrea Griffini <[EMAIL PROTECTED]>
wrote:

>>Tip 1: Once you have data in memory, don't move it, move a pointer or
>>index over the parts you are inspecting.
>>
>>Tip 2: Develop an abhorrence of deleting data.
>
>I've to admit that I also found strange that deleting the
>first element from a list is not O(1) in python. My wild
>guess was that the extra addition and normalization required
>to have insertion in amortized O(1) and deletion in O(1) at
>both ends of a random access sequence was going to have
>basically a negligible cost for normal access (given the
>overhead that is already present in python).

Smth similar happened here - I _assumed_ that since lists in 
Python can hold arbitrary objects, the low level C implementation 
was smth like "array" of pointers to those objects (or offsets of
those objects stored elsewhere). 

If so, deleting an element from a list would merely be deleting a
pointer (or zeroing particular offset to get this object "released"),
which would have negligible cost. 

I've read that Python's memory management technique
is 'reference counting' - it would seem only logical that 
the list is an array (or linked list or linked list of arrays
maybe, as it can grow in size arbitrarily) of such 
references.

>But I'm sure this idea is too obvious for not having been
>proposed, and so there must reasons for refusing it
>(may be the cost to pay for random access once measured was
>found being far from negligible, or that the extra memory
>overhead per list - one int for remembering where the live
>data starts - was also going to be a problem).

But either the book-keeping of offsets or pointers or references 
to list elements has to be done by Python interpreter, oops,
VIRTUAL MACHINE, somehow anyway. 

I don't see why should deleting element from a list be O(n), while
saying L[0]='spam' when L[0] previously were, say, 's', not have the
O(n) cost, if a list in Python is just an array containing the 
objects itself?

Why should JUST deletion have an O(n) cost?



--
I have come to kick ass, chew bubble gum and do the following:

from __future__ import py3k

And it doesn't work.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Writing huge Sets() to disk

2005-01-10 Thread Batista, Facundo
Title: RE: Writing huge Sets() to disk





[Martin MOKREJ?]


#-   I have sets.Set() objects having up to 20E20 items,
#- each is composed of up to 20 characters. Keeping


Are you really sure??



#-   How can I write them efficiently to disk? To be more exact,


I think that there's some mistake here.


At least you'll need a disk of 34694 EXABYTES!!!



.    Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/


  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Writing huge Sets() to disk

2005-01-10 Thread Martin MOKREJŠ
Batista, Facundo wrote:
[Martin MOKREJŠ]
#- > At least you'll need a disk of 34694 EXABYTES!!!
#- 
#- Hmm, you are right. So 20E15 then? I definitely need to be

Right. Now you only need 355 PETABytes. Nowadays disk is cheap, but...
#- in range 1-14. ;-)
Why?
I need to test for occurence every such combination in some real-world
examples. Many many will be missing, and those I have to keep.
I've no clue what size will be the drop, so I rather expect full size.
So, the generated, theoretical lexicon I could generate on the fly,
but the results I have to keep.
Even if I give up on this, can I write Sets onto a disk while keeping
their nice, built-in methods?
M.
--
http://mail.python.org/mailman/listinfo/python-list


Re: syntax error in eval()

2005-01-10 Thread Duncan Booth
harold fellermann wrote:

> Python 2.4 (#1, Dec 30 2004, 08:00:10)
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> class X : pass
> ...
> >>> attrname = "attr"
> >>> eval("X.%s = val" % attrname , {"X":X, "val":5})
> Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 1
>  X.attr = val
> ^
> SyntaxError: invalid syntax
> 
> 
> Does anyone have a clue what might be wrong? Thanks in advance.

What you are doing wrong is attempting to use eval before exhausting all 
the simpler techniques. Why not just call 'setattr'?

>>> setattr(X, 'attr', 5)

BTW, the syntax error is because eval evaluates an expression and 
an assignment statement is a statement not an expression.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: syntax error in eval()

2005-01-10 Thread harold fellermann
Thank you, Duncan and Steven.
I completely forgot about setattr.
Of course that's the way ... as its name might suggest *g*
What you are doing wrong is attempting to use eval before exhausting 
all
the simpler techniques. Why not just call 'setattr'?

setattr(X, 'attr', 5)
BTW, the syntax error is because eval evaluates an expression and
an assignment statement is a statement not an expression.
--
Abandon the search for Truth -- settle for a good fantasy.
--
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread Paul McGuire
"Martin MOKREJ©" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>   I have sets.Set() objects having up to 20E20 items,
> each is composed of up to 20 characters. Keeping
> them in memory on !GB machine put's me quickly into swap.
> I don't want to use dictionary approach, as I don't see a sense
> to store None as a value. The items in a set are unique.
>
>   How can I write them efficiently to disk? To be more exact,
> I have 20 sets. _set1 has 1E20 keys of size 1 character.
>
> alphabet = ('G', 'A', 'V', 'L', 'I', 'P', 'S', 'T', 'C', 'M', 'A', 'Q',
'F', 'Y', 'W', 'K', 'R', 'H', 'D', 'E')
> for aa1 in alphabet:
> # l = [aa1]
> #_set1.add(aa1)
> for aa2 in alphabet:
> # l.append(aa2)
> #_set2.add(''.join(l))
> [cut]
>
>   The reason I went for sets instead of lists is the speed,
> availability of unique, common and other methods.
> What would you propose as an elegant solution?
> Actually, even those nested for loops take ages. :(
> M.

_set1 only has 19 keys of size 1 character - 'A' is duplicated.

Assuming you replace 'A' with another character (say 'Z'), then here is what
you get:
_set1 - 20 elements (20**1)
_set2 - 400 elements (20**2)
_set3 - 8000 elements (20**3)
...
_set20 - 20**20 ~ 10 ^ (1.301*20) or 1E26

If you have no duplicates in your alphabet, then you wont need to use sets,
every combination will be unique.  In this case, just use a generator.

Here's a recursive generator approach that may save you a bunch of nested
editing (set maxDepth as high as you dare):

alphabet = ('G', 'A', 'V', 'L', 'I', 'P', 'S', 'T', 'C', 'M', 'Z', 'Q', 'F',
'Y', 'W', 'K', 'R', 'H', 'D', 'E')

maxDepth = 3

def genNextCombo(root=list(),depth=1):
for a in alphabet:
thisRoot = root + [a]
yield "".join( thisRoot )
if depth < maxDepth:
for c in genNextCombo(thisRoot, depth+1):
yield c

for c in genNextCombo():
print c  # or write to file, or whatever



-- Paul


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Andrey Tatarinov
Nick Coghlan wrote:
And about examples for usage "where" keyword
reading http://manatee.mojam.com/~skip/python/fastpython.html I 
understand that almost every example should use that keyword =)
I suspect polluting the outer namespace would still be faster, since 
Python wouldn't have to create the extra level of scoping all the time.
sure, but just a little bit slower =)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread Martin MOKREJŠ
Robert Brewer wrote:
Martin MOKREJŠ wrote:
 I have sets.Set() objects having up to 20E20 items,
each is composed of up to 20 characters. Keeping
them in memory on !GB machine put's me quickly into swap.
I don't want to use dictionary approach, as I don't see a sense
to store None as a value. The items in a set are unique.
 How can I write them efficiently to disk?

got shelve*?
I know about shelve, but doesn't it work like a dictionary?
Why should I use shelve for this? Then it's faster to use
bsddb directly and use string as a key and None as a value, I'd guess.
Even for that, note that even for data contained in _set11,
the index should be(could be) optimized for keysize 11.
There are no other record-sizes.
Similarly, _set15 has all keys of size 15. In the bsddb or anydbm
and other modules docs, I don't see how to optimize that. Without
this optimization, I think it would be even slower. And shelve
gives me exactly such, unoptimized, general index on dictionary.
Maybe I'm wrong, I'm just a beginner here.
Thanks
M.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Jacek Generowicz
"Anna" <[EMAIL PROTECTED]> writes:

> Jacek Generowicz wrote:
> > "Anna" <[EMAIL PROTECTED]> writes:
> >
> > > With class and def, I at least have a *name* to start with - class
> > > Square pretty obviously is going to have something to do with
> > > geometric shapes, I would hope (or maybe with boring people...).
> >
> > Or maybe with multiplying something by itself. Or maybe the author
> > made some changes in his program, and forgot to rename the class
> > sensibly, and the class' functionality has nothing to do with squares
> > of any sort any more. Or maybe he felt the name "Square" was very
> > appropriate for something else in his program and inadvertently gave
> > the same name to two different entities thereby clobbering the one
> > whose use was intended at this point.
> 
> Idjits abound. ;-)

Yup ... which is one reason why lambda is so useful. Everything there
is to know about it is right in front of your eyes. There is no chance
that some idjit changed the meaning of lambda, or the code which
appears within it (unless that refers to some external names, of
course).

> > So, IIUC, you consider
> >
> >def add_one(x):
> >return x+1
> >
> >map(add_one, seq)
> >
> > to be clearer than
> >
> >map(lambda x:x+1, seq)
> 
> Completely, totally, and unambiguously:

Curious. It's very much the other way around for me.

> the version with the defined function is immediately clear to me;
> the version with the lambda is decipherable, but requires
> deciphering (even at 2nd and 3rd glance).  But first, wouldn't
> something like:
> 
> [x+1 for x in seq]
> 
> be even clearer?

I'm glad you mentioned that. My next question was going to be
something along the lines of what you think of the equivalent list
comprehension, which is spectacularly devoid of any names to give you
any hints whatsoever.

As to whether it is clearer. That depends. I would venture to suggest
that, given a pool of laboratory rats with no previous exposure to
Python, more of them would understand the map-lambda than the list
comprehension. 

There are no words in the list comprehension at all (besides the
common "seq"): it's all syntax. Even if "map" and "lambda" ring no
bells by association with anything you might have learned outside of
Python, they sure are a lot easier to look up in the documentation.

> Given an example more complex (which you must admit, lambdas usually
> are)

Well, they can't be _that_ much more complex in Python :-) But I'll
grant you, they are often more complex that the one above.

> - the name of the function is something my brain can hold on to to
> represent the group of operations; where with the lambda, I need to
> mentally go through each operation each time I try to read it. And the
> more complex f is, the harder time I have holding it all in my head
> while I figure out how to get from the beginning value x to the ending
> value f(x). lambda is an O(N*N) problem for my brain.

Fair enough. If I understand the code just by looking at it, then I
prefer to see it inline. If its meaning isn't obvious immediately,
then I'd go for the named function too. But I still value the ability
to inline-define the function while developing ... even if the inline
function will be outlined in the final product.

But, how do you feel about the individual lines of code in the body of
a multi-line function? They don't have individual names.

> I could see someone more mathematically-minded being happier with
> lambda. It's not, after all, the word "lambda" itself;

Aaah ... you did suggest (upthread) that it was the word itself which
gave you problems ... which is what piqued my interest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-10 Thread Andrey Tatarinov
Nick Coghlan wrote:
Abstract

  The proposal is to add the capacity for statement local namespaces to 
Python. This allows a statement to be placed at the current scope, while 
the statement's 'setup code' is indented after the statement::

   with:
  
I think using 'with' keyword can cause some ambiguity. for example I 
would surely try to write

>>> x = a+b with self:
>>> b = member
and using with at the end of block brings more ambiguity:
>>> stmt1()
>>> stmt2()
>>> with self:
>>> member = stmt3()
compare to:
>>> stmt1()
>>> stmt2()
>>> with:
>>> variable = stmt3()
a way different semantics with just one word added/deleted.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread Martin MOKREJÅ
Paul McGuire wrote:
"Martin MOKREJÂ" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi,
 I have sets.Set() objects having up to 20E20 items,
each is composed of up to 20 characters. Keeping
them in memory on !GB machine put's me quickly into swap.
I don't want to use dictionary approach, as I don't see a sense
to store None as a value. The items in a set are unique.
 How can I write them efficiently to disk? To be more exact,
I have 20 sets. _set1 has 1E20 keys of size 1 character.
alphabet = ('G', 'A', 'V', 'L', 'I', 'P', 'S', 'T', 'C', 'M', 'A', 'Q',
'F', 'Y', 'W', 'K', 'R', 'H', 'D', 'E')
for aa1 in alphabet:
   # l = [aa1]
   #_set1.add(aa1)
   for aa2 in alphabet:
   # l.append(aa2)
   #_set2.add(''.join(l))
[cut]
 The reason I went for sets instead of lists is the speed,
availability of unique, common and other methods.
What would you propose as an elegant solution?
Actually, even those nested for loops take ages. :(
M.

_set1 only has 19 keys of size 1 character - 'A' is duplicated.
Ahh, you are right. That's a typo, yet I have to figure out which char
I have to use. But 'Z' will do for the tests anyway.
Assuming you replace 'A' with another character (say 'Z'), then here is what
you get:
_set1 - 20 elements (20**1)
_set2 - 400 elements (20**2)
_set3 - 8000 elements (20**3)
...
_set20 - 20**20 ~ 10 ^ (1.301*20) or 1E26
If you have no duplicates in your alphabet, then you wont need to use sets,
every combination will be unique.  In this case, just use a generator.
As I noted in later response, actually I will compare these ideal sets to 
some
real world examples. I have no expectation how many entries will be common
and how many unique. The only thing I know even in real world, I might be in
size ranges of 2E6 or perhaps 2E8?
Here's a recursive generator approach that may save you a bunch of nested
editing (set maxDepth as high as you dare):
alphabet = ('G', 'A', 'V', 'L', 'I', 'P', 'S', 'T', 'C', 'M', 'Z', 'Q', 'F',
'Y', 'W', 'K', 'R', 'H', 'D', 'E')
maxDepth = 3
def genNextCombo(root=list(),depth=1):
for a in alphabet:
thisRoot = root + [a]
yield "".join( thisRoot )
if depth < maxDepth:
for c in genNextCombo(thisRoot, depth+1):
yield c
for c in genNextCombo():
print c  # or write to file, or whatever
Works nice, but http://www.python.org/doc/2.3.4/ref/yield.html
doesn't really tell what happens here. :( But is quite fast and
definitely saves those the stupid recursively hand-written for
loops.
Thanks Paul!
M.
--
http://mail.python.org/mailman/listinfo/python-list


ftplib with unknown file names

2005-01-10 Thread rbt
How can I use ftplib to retrieve files when I do not know their names? I 
can do this to get a listing of the directory's contents:

ftp_server.retrlines('LIST')
The output from this goes to the console and I can't figure out how to 
turn that into something I can use to actually get the files (like a 
list of file names). I read a bit about the callback function that can 
be passed to retrlines but I couldn't figure out how to use it.

Any help is appreciated.
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Jeff Shannon
Jacek Generowicz wrote:
"Anna" <[EMAIL PROTECTED]> writes:
But first, wouldn't something like:
[x+1 for x in seq]
be even clearer?
I'm glad you mentioned that. [...]
As to whether it is clearer. That depends. I would venture to suggest
that, given a pool of laboratory rats with no previous exposure to
Python, more of them would understand the map-lambda than the list
comprehension. 
I would venture to suggest the exact opposite, that the syntax of a 
list comprehension is in itself suggestive of its meaning, while 'map' 
and 'lambda' are opaque until you've researched them.  The verb 'to 
map', in this mathematical sense, is not part of standard usage among 
anyone that *I* know.  Instead, they'd speak of doing something for 
(or to) each item in a group -- exactly what list comps express.

Speaking for *this* laboratory rat, at least, map/lambda was always a 
nasty puzzle for me and difficult to sort out.  But when list comps 
were introduced, after reading just a sentence or two on how they 
worked, they were completely clear and understandable -- much more so 
than map/lambda after many months of exposure.

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Importing Problem on Windows

2005-01-10 Thread brolewis
I have a directory that has two files in it:

parse.py
parser.py

parse.py imports a function from parser.py and uses it to parse out the
needed information. On Linux, the following code works without a
problem:

parse.py, line 1:
from parser import regexsearch

However, when I run the same command in Windows, I get the following
error:

ImportError: cannot import name regexsearch
Any suggestions on why this would work on Linux but not on Windows?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: complex numbers

2005-01-10 Thread Alfred Z. Newmane
J|rgen Exner wrote:
> [EMAIL PROTECTED] wrote:
>> #python supports complex numbers.
> [...]
>
> So?
>
>> # Perl doesn't support complex numbers. But there are packages that
>> supports it.
>
> The Math::Complex module is part of the standard installation
> already, no need for any "packages" (whatever that might be).

'package' is a keyword, you should know this :-) Thats an important part 
of most modules.

Actually it seems a lot of people use 'module' and 'package' 
interchangably, both refering to libraries, if you will, the one can 
include in a script, or another package. 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Old Paranoia Game in Python

2005-01-10 Thread [EMAIL PROTECTED]

Lucas Raab wrote:
> [EMAIL PROTECTED] wrote:
> > Aahz wrote:
> >
> >>Trust the computer, the computer is your friend.
> >
> >
> > However, the computer isn't a fuckin' mind reader.
> >
> > If you're going to post source code on the usenet, don't
> > have lines longer than 72 characters. Otherwise you'll
> > find your code has wrapped lines. This not only causes
> > syntax errors in your choose and print statements but
> > also fucks up the formatting of of printed paragraphs.
> >
> > Stupid human.
> >
>
> Temper, temper...

But if I hadn't thrown a temper tantrum, I never would
have learned about pyparsing (which I downloaded and 
installed).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ftplib with unknown file names

2005-01-10 Thread Jeremy Jones
rbt wrote:
How can I use ftplib to retrieve files when I do not know their names? 
I can do this to get a listing of the directory's contents:

ftp_server.retrlines('LIST')
The output from this goes to the console and I can't figure out how to 
turn that into something I can use to actually get the files (like a 
list of file names). I read a bit about the callback function that can 
be passed to retrlines but I couldn't figure out how to use it.

Any help is appreciated.
Thanks!
.nlst(argument) will return a list of file names.  Here are 
the docs for the nlst command:

http://www.python.org/doc/current/lib/ftp-objects.html
HTH,
Jeremy Jones
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-10 Thread Roose

"Paul Rubin"  wrote in message
news:[EMAIL PROTECTED]
> "Roose" <[EMAIL PROTECTED]> writes:
> > Are you actually going to answer any of my questions?  Let's see
> > this "JavaScript task scheduler" you have written!
>
> I wrote it at a company and can't release it.  It ran inside a
> browser.  There was nothing terribly amazing about it.  Obviously the
> tasks it scheduled were not kernel tasks.  Do you know how Stackless
> Python (with continuations) used to work?  That had task switching,
> but those were not kernel tasks either.


Well, then of course you know I have to say:  An OS does not run inside a
browser.  There's a sentence I never thought I'd utter in my lifetime.

So that is an irrelevant example, since it obviously isn't a task scheduler
in the context of this thread.

Anyway, this argument is going nowhere... I will admit that people have
pointed out things here that are interesting like the attempts to embed
Python in a kernel.  But the point was that the OP was looking for an easier
way to write an OS, and thought that might be to do it in Python, and I
think I gave some good guidance away from that direction.  That is mostly
what I care about.

These other arguments are academic, and of course I am not trying to stop
anyone from trying anything.  When I we see real working example, then we
will all have a better idea of what the problems are, and how much of it can
realistically be implemented in an interpreted language.  Frankly I don't
think that will come for about 10 years if ever, but hey prove me wrong.


-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Writing huge Sets() to disk

2005-01-10 Thread Robert Brewer
Martin MOKREJŠ wrote:
> Robert Brewer wrote:
> > Martin MOKREJŠ wrote:
> > 
> >>  I have sets.Set() objects having up to 20E20 items,
> >>each is composed of up to 20 characters. Keeping
> >>them in memory on !GB machine put's me quickly into swap.
> >>I don't want to use dictionary approach, as I don't see a sense
> >>to store None as a value. The items in a set are unique.
> >>
> >>  How can I write them efficiently to disk?
> > 
> > 
> > got shelve*?
> 
> I know about shelve, but doesn't it work like a dictionary?
> Why should I use shelve for this? Then it's faster to use
> bsddb directly and use string as a key and None as a value, I'd guess.

If you're using Python 2.3, then a sets.Set *is* implemented with a dictionary, 
with None values. It simply has some extra methods to make it behave like a 
set. In addition, the Set class already has builtin methods for pickling and 
unpickling.

So it's probably faster to use bsddb directly, but why not find out by trying 2 
lines of code that uses shelve? The time-consuming part of your quest is 
writing the timed test suite that will indicate which route will be fastest, 
which you'll have to do regardless.


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Anna
Same here.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Anna
You cut something from that...

"""It's not, after all, the word "lambda" itself; I would still
have some issues with using, say "function", instead of "lambda", but
at least then I would immediately know what I was looking at..."""

I would have fewer ambiguities about using, say "func" rather than
lambda. Lambda always makes me feel like I'm switching to some *other*
language (specifically, Greek - I took a couple of semesters of Attic
Greek in college and quite enjoyed it.) But, the fact that lambda
doesn't MEAN anything  (and has come - I mean - DELTA at least has a
fairly commonly understood meaning, even at high-school level math.
But, lambda? If it was "func" or "function" or even "def", I would be
happier. At least that way I'd have some idea what it was supposed to
be...

BTW - I am *quite* happy with the proposal for "where:" syntax - I
think it handles the problems I have with lambda quite handily. 

Anna

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread Adam DePrince
On Mon, 2005-01-10 at 11:11, Martin MOKREJ¦ wrote:
> Hi,
>   I have sets.Set() objects having up to 20E20 items,
> each is composed of up to 20 characters. Keeping
> them in memory on !GB machine put's me quickly into swap.
> I don't want to use dictionary approach, as I don't see a sense
> to store None as a value. The items in a set are unique.

Lets be realistic.  Your house is on fire and you are remodeling the
basement.

Assuming you are on a 64 bit machine with full 64 bit addressing, your
absolute upper limit on the size of a set is 2^64, or
18446744073709551616 byte.  Your real upper limit is at least an order
of magnitude smaller.

You are asking us how to store 20E20, or 20, items
in a Set.  That is still an order of magnitude greater than the number
of *bits* you can address.  Your desktop might not be able to enumerate
all of these strings in your lifetime, much less index and store them.

We might as well be discussing the number of angles that can sit on the
head of a pin.  Any discussion of a list vs Set/dict is a small micro
optimization matter dwarfed by the fact that there don't exist machines
to hold this data.  The consideration of Set vs. dict is an even less
important matter of syntactic sugar.

To me, it sounds like you are taking an AI class and trying to deal with
a small search space by brute force.  First, stop banging your head
against the wall algorithmically.  Nobody lost their job for saying NP
!= P.  Then tell us what you are tring to do; perhaps there is a better
way, perhaps the problem is unsolvable and there is a heuristic that
will satisfy your needs. 



Adam DePrince 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread Martin MOKREJŠ
Robert Brewer wrote:
Martin MOKREJŠ wrote:
Robert Brewer wrote:
Martin MOKREJŠ wrote:

I have sets.Set() objects having up to 20E20 items,
each is composed of up to 20 characters. Keeping
them in memory on !GB machine put's me quickly into swap.
I don't want to use dictionary approach, as I don't see a sense
to store None as a value. The items in a set are unique.
How can I write them efficiently to disk?

got shelve*?
I know about shelve, but doesn't it work like a dictionary?
Why should I use shelve for this? Then it's faster to use
bsddb directly and use string as a key and None as a value, I'd guess.

If you're using Python 2.3, then a sets.Set *is* implemented with
Yes, I do.
a dictionary, with None values. It simply has some extra methods to
make it behave like a set. In addition, the Set class already has
builtin methods for pickling and unpickling.
Really? Does Set() have such a method to pickle efficiently?
I haven't seen it in docs.
So it's probably faster to use bsddb directly, but why not find out
by trying 2 lines of code that uses shelve? The time-consuming part
Because I don't know how can I afect indexing using bsddb, for example.
For example, create index only for say keysize-1 or keysize-2 chars
of a keystring.
How to delay indexing so that index isn't rebuild after every addiotion
of a new key? I want to do it a the end of the loop adding new keys.
Even better, how to turn off indexing completely (to save space)?
of your quest is writing the timed test suite that will indicate
which route will be fastest, which you'll have to do regardless.
Unfortunately, I'm hoping to get first an idea what can be made
faster and how when using sets and dictionaries.
M.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >