Re: python bug in this list implementation?

2005-12-27 Thread Fredrik Lundh
Chris Smith wrote:

> I've been working on some multi-dimensional lists and I've encountered some
> very strange behaviour in what appears to be simple code, I'm using python
> 2.4.2 and IDLE. If anyone can tell me why it's behaving so strange please
> let me know, any improvements to my general coding style are also
> appreciated.
> code below:
>
> import sys
> import copy
>
> grid = []
> oGrid = []
> sGrid = []
>
> def createGrid():
> f = open(r"...sudoku.txt", "rb") ## see attached for the file.
>
> for line in f:
> aLine = line.strip().split(',')
> if aLine != [""]:
> for i in xrange(len(aLine)):
> aLine[i] = int(aLine[i])
> grid.append(aLine)

at this point, grid contains a list of lists.

> oGrid = copy.deepcopy(grid)

if you assign to a name inside a function, that name is considered to be
*local*, unless you specify otherwise.  in other words, this doesn't touch
the *global* (module-level) oGrid variable.

> sGrid.append(copy.deepcopy(grid))

here you add a list of lists to a list.  the result is a list with a single 
item.

> def printGrid():
> print "original grid:"
> for line in oGrid:
> print line#why doesn't this print anything?

because the *global* oGrid is still empty.

> print "S grid:"
> for line in sGrid:
> print line  #this prints the grid but the formatting is all over the
> place.

because sGrid contains a single item; a copy of your original grid.

> print "Iteration grid: "
> for line in grid:
> print line  #works fine!

as expected.

I suggest reading up on list methods and global variables in your favourite
python tutorial.

also read:

http://www.catb.org/~esr/faqs/smart-questions.html#id3001405





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


python bug in this list implementation?

2005-12-27 Thread Chris Smith
Hi,

I've been working on some multi-dimensional lists and I've encountered some
very strange behaviour in what appears to be simple code, I'm using python
2.4.2 and IDLE. If anyone can tell me why it's behaving so strange please
let me know, any improvements to my general coding style are also 
appreciated.
code below:

import sys
import copy

grid = []
oGrid = []
sGrid = []

def createGrid():
f = open(r"...sudoku.txt", "rb") ## see attached for the file.

for line in f:
aLine = line.strip().split(',')
if aLine != [""]:
for i in xrange(len(aLine)):
aLine[i] = int(aLine[i])
grid.append(aLine)

oGrid = copy.deepcopy(grid)
sGrid.append(copy.deepcopy(grid))


def printGrid():
print "original grid:"
for line in oGrid:
print line#why doesn't this print anything?

print "S grid:"
for line in sGrid:
print line  #this prints the grid but the formatting is all over the
place.

print "Iteration grid: "
for line in grid:
print line  #works fine!

if __name__ == "__main__":
createGrid()
printGrid()

##PRODUCES THE FOLLOWING OUTPUT:
##
##original grid:
##S grid:
##[[0, 0, 0, 1, 5, 0, 0, 7, 0], [1, 0, 6, 0, 0, 0, 8, 2, 0], [3, 0, 0, 8, 6,
0, 0, 4, 0], [9, 0, 0, 4, 0, 0, 5, 6, 7], [0, 0, 4, 7, 0, 8, 3, 0, 0], [7,
3, 2, 0, 1, 6, 0, 0, 4], [0, 4, 0, 0, 8, 1, 0, 0, 9], [0, 1, 7, 0, 0, 0, 2,
0, 8], [0, 5, 0, 0, 3, 7, 0, 0, 0]]
##Iteration grid:
##[0, 0, 0, 1, 5, 0, 0, 7, 0]
##[1, 0, 6, 0, 0, 0, 8, 2, 0]
##[3, 0, 0, 8, 6, 0, 0, 4, 0]
##[9, 0, 0, 4, 0, 0, 5, 6, 7]
##[0, 0, 4, 7, 0, 8, 3, 0, 0]
##[7, 3, 2, 0, 1, 6, 0, 0, 4]
##[0, 4, 0, 0, 8, 1, 0, 0, 9]
##[0, 1, 7, 0, 0, 0, 2, 0, 8]
##[0, 5, 0, 0, 3, 7, 0, 0, 0]



begin 666 sudoku.txt
M,"PP+# L,2PU+# L,"PW+# -"C$L,"PV+# L,"[EMAIL PROTECTED],BPP#0HS+# L,"PX
M+#8L,"PP+#0L, T*#0HY+# L,"PT+# L,"PU+#8L-PT*,"[EMAIL PROTECTED]
M,RPP+# -"Chttp://mail.python.org/mailman/listinfo/python-list


Re: fetching images from web?

2005-12-27 Thread bonono
may be using wget/curl but then it is no longer python ;-)

[EMAIL PROTECTED] wrote:
> hi, i want to automate some tasks of gathering photos from web, i tried
> urllib/urllib2, both ended up without much success (saved gifs with
> only a border, nothing else)..
>
> the code i used was:
>
> >>> data = 
> >>> urllib2.urlopen("http://aspn.activestate.com/ASPN/img/komodo_aspn_other.gif";)
> >>>   #was looking through cookbook, so i used that as a sample image
> >>> data = data.read()
> >>> file = open("f:/test.gif", "w")
> >>> file.write(data)
> >>> file.close()
>
>
> can someone suggest a better way (or what's wrong with urllib/urllib2)?
> thanks alot!

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


Re: fetching images from web?

2005-12-27 Thread randomtalk
ah, wb works :D thanks alot!

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


Re: fetching images from web?

2005-12-27 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:

> hi, i want to automate some tasks of gathering photos from web, i tried
> urllib/urllib2, both ended up without much success (saved gifs with
> only a border, nothing else)..
> 
> the code i used was:
> 
> >>> data = urllib2.urlopen(
   "http://aspn.activestate.com/ASPN/img/komodo_aspn_other.gif";)
> >>>  #was looking through cookbook, so i used that as a sample image
> >>> data = data.read()
> >>> file = open("f:/test.gif", "w")

Since you appear to want to write binary data, you should use 'wb', not
'w', as the "mode".


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


Re: fetching images from web?

2005-12-27 Thread Mike Meyer
[EMAIL PROTECTED] writes:
> hi, i want to automate some tasks of gathering photos from web, i tried
> urllib/urllib2, both ended up without much success (saved gifs with
> only a border, nothing else)..

Um - what else did you expect? You fetched a gif, you should get a gif.

> the code i used was:
>
 data = 
 urllib2.urlopen("http://aspn.activestate.com/ASPN/img/komodo_aspn_other.gif";)
   #was looking through cookbook, so i used that as a sample image
 data = data.read()
 file = open("f:/test.gif", "w")
 file.write(data)
 file.close()

This looks like it works fine to me.

> can someone suggest a better way (or what's wrong with urllib/urllib2)?
> thanks alot!

Can you be more explicit about what you think is wrong with what
you're doing?

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: predicting function calls?

2005-12-27 Thread Mike Meyer
[EMAIL PROTECTED] (Roy Smith) writes:
> Objects can have attributes (data) and operations associated with
> them.  It would be very convenient to use the "." syntax to access
> both of these, i.e. be able to say:
>
> print handle.someAttribute
> print handle.someOperation (arg1, arg2)
>
> I'm using __getattr__() to process both of these constructs, and
> herein lies the rub; I need to do different things depending on
> whether the name is an attribute or an operation.  I can ask the DB
> for a list of the names of all the operations supported by a given
> object, but that's a fairly expensive thing to do, so I'd rather avoid
> it if possible.  It would be really nice if I had some way to find
> out, from inside __getattr__(), if the value I'm about to return will
> get called as a function (i.e., the name is followed by an open
> paren).  I can't see any way to do that, but maybe I'm missing
> something?
>
> Any ideas?

Fnorb (a pure-Python CORBA orb) dealt with this by not allowing
attributes per se. Instead, it provided _get_AttributeName and
_set_AttributeName as appropriate for each attribute in the IDL. Doing
this means that *everything* you hand back from __getattr__ is going
to be a callable, and presumably called at some point.

Properties postdate Fnorb, so weren't considered in it's design. You
might be able to do something with them as well.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how-to POST form data to ASP pages?

2005-12-27 Thread Mike Meyer
"livin"  writes:
> Mike,
> I appreciate the help... I'm a noobie to Python. I know vbscript & jscript 
> but nothing else.
>
> I obviously do not need to submit the images
>
> my code looks like this but it is not working... any ideas?
>
>
>   params = urllib.urlencode({'action': 'hs.ExecX10ByName "Kitchen 
> Espresso Machine", "Off", 100'})
>   urllib.urlopen("http://192.168.1.11:80/hact/kitchen.asp";, params)

No ideas. What does "not working" mean? Do you get a traceback from
Python? If so, share it - cause what I see here isn't legal Python. Do
you get an error message from the kitchen.asp form handler? If so,
...

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

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


fetching images from web?

2005-12-27 Thread randomtalk
hi, i want to automate some tasks of gathering photos from web, i tried
urllib/urllib2, both ended up without much success (saved gifs with
only a border, nothing else)..

the code i used was:

>>> data = 
>>> urllib2.urlopen("http://aspn.activestate.com/ASPN/img/komodo_aspn_other.gif";)
>>>   #was looking through cookbook, so i used that as a sample image
>>> data = data.read()
>>> file = open("f:/test.gif", "w")
>>> file.write(data)
>>> file.close()


can someone suggest a better way (or what's wrong with urllib/urllib2)?
thanks alot!

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


Re: query on python list

2005-12-27 Thread Mike Meyer
[EMAIL PROTECTED] writes:
> hi tim
> thanks for the help
> acutally i dint tell u the whole problem
> i have list of lists, for ex
>
> list1 =[ ['a','b','c','d','e'] , ['1','2','3','4'] ,  ['A','B','C','D']
> ]
>
> and another list
>
> list2 = ['1','2','5',4]
>
> now am searching the items of list2 in list1 as below
>
> Found = True
> for i in list1:
> for j in i:
> if not list2[1] == j or not list2[2] == j:
> if not list2[0] == j:
> Found = False
> elif list2[0] == j:
> Found = True
> break
>
> now though it finds the the key in between and sets the "Found=True",
> but later in the next list of if one item doesnt match it sets again
> Found = False
>
> i hope am clear this time

You have half the solution. Basically, you should set Found to one
state, and then only set it againn if it changes. For instance:

Found = True
for i in list1:
for j in i:
if not list2[1] == j or not list2[2] == j:
   if not list2[0] == j:
  Found = False

This will exit the outer loop with Found being False if and only if
the nested if's in your inner loop set it to False; you never need to
set it to True. Alternatively, set the initial state to False, and
only set it to True if you find something.

For efficiency, you can break from the inner loop, and then check
found after the inner loop and break a second time if it's changed.

BTW, the nested ifs in your inner loop don't do what your description
says they should.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any Adobe Reader like apps written in python, for examination?

2005-12-27 Thread Alex Gittens
Yeah, pygame is not what I'm looking for. I'm looking for a good
example of cross platform non-trivial page-layout and font handling.
The project I'm working on-- a typographically correct interface to a
CAS-- requires pixel-perfect font handling.

 I'll definitely look into Grail: I'm sure as a browser it has to
address these problems. But I'm open to further suggestions.

Thanks,
Alex

On 12/26/05, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Alex Gittens <[EMAIL PROTECTED]> wrote:
> > Is anyone aware of any applications that handle font and graphics
> > display--- something like Adobe Reader--- that are written in Python,
> > and the code is available for examination? It doesn't matter what GUI
> > toolkit is used.
> >
>
> Grail comes to my mind immediately, it is however rather dated.
> Otherwise, displaying simple graphics and text in pygame is trivial -
> but it is not the right way if you need a GUI.
>
>
> --
>  ---
> | Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
> | __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
>  ---
> Antivirus alert: file .signature infected by signature virus.
> Hi! I'm a signature virus! Copy me into your signature file to help me spread!
> --
> http://mail.python.org/mailman/listinfo/python-list


--
ChapterZero: http://tangentspace.net/cz/
-- 
http://mail.python.org/mailman/listinfo/python-list


predicting function calls?

2005-12-27 Thread Roy Smith
I think I know the answer to this, but I'll ask it just in case
there's something I hadn't considered...

I'm working on a python interface to a OODB.  Communication with the
DB is over a TCP connection, using a model vaguely based on CORBA.
I'll be creating object handles in Python which are proxies for the
real objects in the database by doing something like:

handle = connection.getObjectHandle (className, instanceName)

Objects can have attributes (data) and operations associated with
them.  It would be very convenient to use the "." syntax to access
both of these, i.e. be able to say:

print handle.someAttribute
print handle.someOperation (arg1, arg2)

I'm using __getattr__() to process both of these constructs, and
herein lies the rub; I need to do different things depending on
whether the name is an attribute or an operation.  I can ask the DB
for a list of the names of all the operations supported by a given
object, but that's a fairly expensive thing to do, so I'd rather avoid
it if possible.  It would be really nice if I had some way to find
out, from inside __getattr__(), if the value I'm about to return will
get called as a function (i.e., the name is followed by an open
paren).  I can't see any way to do that, but maybe I'm missing
something?

One possibility would be to use different syntaxes for attributes and
operations, i.e:

print handle["someAttribute"]
print handle.someOperation (arg1, arg2)

but I really want to avoid having to do that for a variety of reasons,
not the least of which is syntax similarity with a legacy system.

The best I've come up with so far is doing the expensive "get a list
of operations for this class" call the first time I see an object of a
given class and caching the list.  The problem there is that this is a
very dynamic system.  It may be possible to add new operations on the
fly and I don't have any good way to invalidate the cache.

Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: libxml2dom problems

2005-12-27 Thread ankit
Thanks .. frederik.
The reason for posting the problem 2 times is that there might be some
problem yesterday with the google groups server . After posting the
mesage I cant see it on the board. That's why I posted again.

anyway thanks for the help

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


Re: how-to POST form data to ASP pages?

2005-12-27 Thread livin
Mike,
I appreciate the help... I'm a noobie to Python. I know vbscript & jscript 
but nothing else.

I obviously do not need to submit the images

my code looks like this but it is not working... any ideas?


  params = urllib.urlencode({'action': 'hs.ExecX10ByName "Kitchen 
Espresso Machine", "Off", 100'})
  urllib.urlopen("http://192.168.1.11:80/hact/kitchen.asp";, params)



"Mike Meyer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "livin"  writes:
>> I need to post form data to an ASP page that looks like this on the page
>> itself...
>> > align='absmiddle' width=16 height=16 title='Off'>> value='Image' name='Action'>
>> I've been trying this but I get a syntax error...
>>   params = urllib.urlencode({'hidden': 'hs.ExecX10ByName "Kitchen
>> Espresso Machine", "On", 100'})
>>   urllib.urlopen("http://192.168.1.11:80/hact/kitchen.asp";, params)
>
> urlencode doesn't care about the type of the input element (or that
> the page is ASP), just the name/value pairs. You want:
>
>   params = urllib.urlencode({'Action': 'Image', ...})
>
> The provided HTML doesn't say what the name of the second hidden input
> field is. It's not at all clear what should be passed to the server in
> this case.
>
> It looks like you tried to break a string across a line boundary, but
> that may be your posting  software. If you did, then that's what's
> generating a syntax error, and a good indication that you should try
> reading the tutorial.
>
> -- 
> Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more 
> information. 


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


Re: Beautiful Python

2005-12-27 Thread Steven D'Aprano
On Tue, 27 Dec 2005 21:35:46 -0600, news wrote:

>> Sometimes putting import statements at the beginning is not feasible
>> (i.e. only when some condition has been met), as importing has some
>> impact on program execution (importing executes code in imported
>> module). This does not resemble Java imports (I don't know Perl).
>> 
>> -- 
> Wow ?!   I've only started looking at python but that sounds like very
> dangerous programming !  Can you give an example.

Dangerous? Why? What's the worst that can happen in:

import parrot
...code...
import aardvark
...code...

that can't happen with this?

import parrot
import aardvark
...code...
...code...



> BTW this topic relates to a recent point raised by the C man's
> [I think Richie, dated ca. 1973] crit of Pascal. He said that
> Pascal's restriction of not being able to declare globals, near
> where they were needed, was bad.  And I thought so too, before I
> considered that the programmer must KNOW that they are global.
> Ie. the ability to declare them at a 'nice' place is just syntactic
> sugar, hiding the reality the globals are bad, and have to be avoided
> and respected.

But Pascal still allows you to use globals.

"Avoid globals" is excellent advise and a good guideline, but if you want
a Bondage and Domination language that prohibits them, Python is not the
language for you.

Look at it this way: the Python interactive interpreter is perhaps the
single most useful feature of Python. You want to be able to use import in
interactive sessions, right? You want to be able to do this:

py> x = 32.2/4.5
py> math.log(x)  # oops, forgot to import math first...
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'math' is not defined
py> import math
py> math.log(x)
1.9678890557740887

without having to exit the session, restart, and import everything you
think you might need.

So Python has to allow imports in the middle of code. So why enforce the
guideline "all imports at the beginning of a module or script"? A module
is just another object in Python, why treat it differently from other
objects?



-- 
Steven.

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


Re: HTMLGen- Table Align property

2005-12-27 Thread Dave Benjamin
Cappy2112 wrote:
> Table and TableLite are different classes. Tablelite requires a little
> more work, and I will ave to rewrite some code to use it.
> 
> I am using Table a tthe moment

Well, as far as I know, wrapping a DIV align="center" around a TABLE 
should produce the same effect as giving the TABLE an align="center".

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


Re: HTMLGen- Table Align property

2005-12-27 Thread Cappy2112
Table and TableLite are different classes. Tablelite requires a little
more work, and I will ave to rewrite some code to use it.

I am using Table a tthe moment


>>ith a "style" attribute (or using the TableLite class, which also
>>accepts a "style" attribute), and setting the "text-align" property:
>>http://www.w3schools.com/css/pr_text_text-align.asp

I'm not familiar with tall the details of CSS at the moment, nad
learning it would only slow down my progress.

Maybe I'll just add the align property to the class


Thanks for your help

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


problem with pyHook module

2005-12-27 Thread Chris Westbrook
I want to use the pyHook module to capture all keyboard input and write it 
to a file.  I have a script that works fine with the command prompt, but I 
have a few issues I need help with.  First, I want to be able to set up an 
html page that has a link to this script and have it start running and 
collecting output, and then use some keystroke like alt+f4 to terminate the 
application.  It seems when I run this script from internet explorer after 
placing it in cgi-bin, the log file gets created but nothing is written to 
it.  i'm running xampp with python 24 and all the necessary stuff. 
Eventually I'd like to try to get the shift key with a letter to indicate an 
upper cased letter, but first I at least want to get all the keys written to 
a file.  Can anyone help?  The sscript I'm starting with is below.
#!c:\Python24\python.exe
print "Content-type:text/html\n\n";
import pyHook
f = open('file.log','w')
def onKeyboardEvent(event):

 f.write(event.Key)

 return True
hm = pyHook.HookManager()
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
if __name__ == '__main__':
  import pythoncom
  pythoncom.PumpMessages() 

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


Re: python coding contest

2005-12-27 Thread Remi Villatel
Christian Tismer wrote:

>>> I feel that python is more beautiful and readable, even if you write
>>> short programs.

> Looking at what I produced the last days, I'm not convinced...

Me neither. Especially since I've taken the one-liner road. Python can 
be very unreadable... sometimes.

> And that's what puzzled me a bit about the approach and the intent
> of this contest: Should this evolute into a language war about
> goals (shortness, conciseness, brevity, whatnot) that Python
> doesn't have as its main targets?

Maybe to prove to the others that Python is a "real" language that can 
produce "uglinesses" too?

> Sure, I see myself hacking this unfortunate little 7-seg code
> until it becomes unreadable for me, the trap worked for me,
> but why do I do this???

For the pleasure of twisting your mind in every possible way, for the 
challenge, for the luxury price if you win? Whatever... I'm trapped too 
and I can't give any reason off the top of my head.

[---CUT---]
> I think it is legal to use any standard pre-installed package you
> like, if it belongs to the set of default batteries included.
[---CUT---]

If you use more than the built-ins, you've already lost. It costs you at 
least 9 bytes, well, 10 since I don't know any module with a 
single-letter name.

"\t"+"import"+" "+name_of_module+"\n"

And knowing how much I struggled to remove the last 10 bytes I removed 
from my code, the idea doesn't sound very attractive.

> After all, I'd really love to set up another contest with
> different measures and criteria.

Go on! I don't think that "shortest code" is a very pythonic goal if you 
count in bytes. The same contest with the length of the code measured in 
  "pythonic units" would be better. When I say "pythonic unit", I mean 
to count 1 unit for each variable, literal, operator or key-word. That 
would be more pythonic.

...but maybe less challenging. To try to do with Python things it wasn't 
meant to do is more "fun" for a contest.  ;-)

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


Re: help with lists and writing to file in correct order

2005-12-27 Thread homepricemaps
hey steven-your examlpe was very helpful. is there a paragraph symbolg
missing in

fp.write("Food = %s, store = %s, price = %s\n" % triplet


Steven D'Aprano wrote:
> On Mon, 26 Dec 2005 20:56:17 -0800, homepricemaps wrote:
>
> > sorry for asking such beginner questions but i tried this and nothing
> > wrote to my text file
> >
> > for food, price, store in bs(food, price, store):
> > out = open("test.txt", 'a')
> > out.write (food + price + store)
> > out.close()
>
> What are the contents of food, price and store? If "nothing wrote to my
> text file", chances are all three of them are the empty string.
>
>
> > while if i write the following without the for i at least get
> > something?
> > out = open("test.txt", 'a')
> > out.write (food + price + store)
> > out.close()
>
> You get "something". That's not much help. But I predict that what you are
> getting is the contents of food price and store, at least one of which are
> not empty.
>
> You need to encapsulate your code by separating the part of the code that
> reads the html file from the part that writes the text file. I suggest
> something like this:
>
>
> def read_html_data(name_of_file):
> # I don't know BeautifulSoup, so you will have to fix this...
> datafile = BeautifulSoup(name_of_file)
> # somehow read in the foods, prices and stores
> # for each set of three, store them in a tuple (food, store, price)
> # then store the tuples in a list
> # something vaguely like this:
> data = []
> while 1:
> food = datafile.get("food")  # or whatever
> store = datafile.get("store")
> price = datafile.get("price")
> data.append( (food,store,price) )
> datafile.close()
> return data
>
> def write_data_to_text(datalist, name_of_file):
> # Expects a list of tuples (food,store,price). Writes that list
> # to name_of_file separated by newlines.
> fp = file(name_of_file, "w")
> for triplet in datalist:
> fp.write("Food = %s, store = %s, price = %s\n" % triplet
> fp.close()
> 
> 
> Hope this helps.
> 
> 
> 
> -- 
> Steven.

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


Re: HTMLGen- Table Align property

2005-12-27 Thread Dave Benjamin
Cappy2112 wrote:
> Does anyone know if the table align property is available in
> HTMLgen.Table?
> The docs don't show it, but I find it hard to believe that it is not
> available.
> 
> I want to center the table.
> Only the cell align propterty is available

 >>> print HTMLgen.TableLite(align="center")


 >>> print HTMLgen.Div(align="center")

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


Re: HTMLGen- Table Align property

2005-12-27 Thread Dave Benjamin
Cappy2112 wrote:
> Does anyone know if the table align property is available in
> HTMLgen.Table?
> The docs don't show it, but I find it hard to believe that it is not
> available.
> 
> I want to center the table.
> Only the cell align propterty is available

I've never used HTMLgen, but you might try wrapping your table in a DIV 
with a "style" attribute (or using the TableLite class, which also 
accepts a "style" attribute), and setting the "text-align" property:

http://www.w3schools.com/css/pr_text_text-align.asp

Hope this helps,
Dave
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: query on python list

2005-12-27 Thread muttu2244
hi tim
thanks for the help
acutally i dint tell u the whole problem
i have list of lists, for ex

list1 =[ ['a','b','c','d','e'] , ['1','2','3','4'] ,  ['A','B','C','D']
]

and another list

list2 = ['1','2','5',4]

now am searching the items of list2 in list1 as below

Found = True
for i in list1:
for j in i:
if not list2[1] == j or not list2[2] == j:
if not list2[0] == j:
Found = False
elif list2[0] == j:
Found = True
break

now though it finds the the key in between and sets the "Found=True",
but later in the next list of if one item doesnt match it sets again
Found = False

i hope am clear this time

how to keep the Found = True for always if at all i find the item even
once.

thanks again in advance
yogi

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


HTMLGen- Table Align property

2005-12-27 Thread Cappy2112
Does anyone know if the table align property is available in
HTMLgen.Table?
The docs don't show it, but I find it hard to believe that it is not
available.

I want to center the table.
Only the cell align propterty is available

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


Re: csv file how to modify the row

2005-12-27 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote:

> On Tue, 27 Dec 2005 19:24:57 -0800, Alex Martelli wrote:
> 
> > Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> > 
> >> Why are you calling it a Comma Separated Values file when there are no
> >> commas separating values in it?
> > 
> > It's common usage
> 
> Well you learn something new every day. Of course I know about
> tab-delimited files and what-not, but that's the first time I've come
> across somebody calling one a CSV file.

I realize that calling "a csv file" something that uses a delimiter
other than comma may feel weird, but we've had csv in the standard
Python library for a while, and it's hard to think of any other wholly
generic monicker.  Maybe you can think of the "c" as standing for
"character" (not sure the delimiter has to be ONE character, tho;-)...


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


Re: csv file how to modify the row

2005-12-27 Thread Steven D'Aprano
On Tue, 27 Dec 2005 19:24:57 -0800, Alex Martelli wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> 
>> Why are you calling it a Comma Separated Values file when there are no
>> commas separating values in it?
> 
> It's common usage

Well you learn something new every day. Of course I know about
tab-delimited files and what-not, but that's the first time I've come
across somebody calling one a CSV file.


-- 
Steven.

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


Re: Beautiful Python

2005-12-27 Thread news
In article <[EMAIL PROTECTED]>, Jarek Zgoda <[EMAIL PROTECTED]> wrote: 

> Gekitsuu napisal(a):
> 
> > use strict;
> > use WWW::Mechanize;
> > use CGI;
> > 
> > This seems to be the de facto standard in the Perl community but in
> > python it seems most of the code I look at has import statements
> > everywhere in the code. Is there a sound reason for putting the imports
> > there are are developers just loading modules in as they need them. I
> > own Damian Conway's book of Perl Best Practices and it seems from a
> > maintainability standpoint  that having all the modules declared at the
> > beginning would make it easier for someone coming behind you to see
> > what other modules they need to use yours. Being new I didn't know if
> > there was a performance reason for doing this or it is simply a common
> > habit of developers.
> 
> Sometimes putting import statements at the beginning is not feasible
> (i.e. only when some condition has been met), as importing has some
> impact on program execution (importing executes code in imported
> module). This does not resemble Java imports (I don't know Perl).
> 
> -- 
Wow ?!   I've only started looking at python but that sounds like very
dangerous programming !  Can you give an example.

BTW this topic relates to a recent point raised by the C man's
[I think Richie, dated ca. 1973] crit of Pascal. He said that
Pascal's restriction of not being able to declare globals, near
where they were needed, was bad.  And I thought so too, before I
considered that the programmer must KNOW that they are global.
Ie. the ability to declare them at a 'nice' place is just syntactic
sugar, hiding the reality the globals are bad, and have to be avoided
and respected.

== Chris Glur.



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


Re: query on python list

2005-12-27 Thread Tim Hochberg
[EMAIL PROTECTED] wrote:
> hi all
> am searching for a key in a list, am using
> 
>   Found = 0
>   for item in list:
>  if not key == item:
>  Found = 0
>  elif key == item:
>  Found =1
> 
> Now based on the Found value i ll manipulate the list.
> but whenever the "key and item" doesnt match it makes "Found = 0", even
> though i have an item that matches the key, but it overwrites the Found
> variable to 0, in the next loop when "key ! = item", and hence all my
> calculations are going wrong,
> If i find a key in my list, some how the variable "Found " should be
> 1,till it comes out of the loop.
> 
> How can i do that.

Well, one way would be:

Found = False
for item in list:
   if key == item:
  Found = True
  break

or maybe:

for item in list:
   if key == item:
  Found = True
  break
else:
   Found = False

but a better way would be:

Found = (key in list)


-tim

> 
> thanks in advance
> yogi
> 

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


query on python list

2005-12-27 Thread muttu2244
hi all
am searching for a key in a list, am using

  Found = 0
  for item in list:
 if not key == item:
 Found = 0
 elif key == item:
 Found =1

Now based on the Found value i ll manipulate the list.
but whenever the "key and item" doesnt match it makes "Found = 0", even
though i have an item that matches the key, but it overwrites the Found
variable to 0, in the next loop when "key ! = item", and hence all my
calculations are going wrong,
If i find a key in my list, some how the variable "Found " should be
1,till it comes out of the loop.

How can i do that.

thanks in advance
yogi

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


Re: csv file how to modify the row

2005-12-27 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote:

> Why are you calling it a Comma Separated Values file when there are no
> commas separating values in it?

It's common usage -- the Python standard library's csv also lets you
parse files where the separator is not a comma -- you just need to have
an explicit 'delimiter' (the comma is just the default value for this);
indeed, class csv.excel_tab has an explicit delimiter set to '\t'.


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


Re: python coding contest

2005-12-27 Thread py pan
On 12/27/05, Christian Tismer <[EMAIL PROTECTED]> wrote:
And we are of course implementing algorithms with a twisted goal-setin mind: How to express this the shortest way, not elegantly,just how to shave off one or even two bytes, re-iterating thepossible algorithms again and again, just to find a version that is
lexically shorter? To what a silly, autistic crowd of insane peopledo I belong? But it caught me, again!I personally think that it's a good practice. The experiences gatheredmight be useful in other applications in the future. That's where the
excitement of learning new things is about. Actually, I don't see so much applications
for the given problem, Something like this:http://j.domaindlx.com/elements28/wxpython/LEDCtrl.htmlconvinced me that there are application of this problem. 

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

Re: python coding contest

2005-12-27 Thread Tim Hochberg
Christian Tismer wrote:
[SNIP]

> And then help me to setup a different contest about content -- chris

As usual, I expect that actually having some working code measuring 
'Pythonic' length (and I'm sure we could get into all sorts of fun 
arguments about the exact definition of that) would go a long way 
towards convincing the next contest thrower who's measuring length to 
use something a little less distorting than program length.

I've been thinking about writing something, but I've been distracted. 
Perhaps I'll take a stab at it tomorrow and see what I come up with.

That being said, the result I've come up with for the contest are pretty 
cool in a perverse way, at least while there it's spread out over six 
lines. Once it gets folded up, it become unbearable. And, sadly, it only 
saves 3 characters. If one was ignoring leading and trailing whitespace 
the unfolded version would be the much shorter of the two, but ya gotta 
play with the rules as they is.

-tim


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


Re: csv file how to modify the row

2005-12-27 Thread Steven D'Aprano
On Tue, 27 Dec 2005 14:45:16 -0800, muttu2244 wrote:

> Hi everybody
> 
> 
> Am trying to read a csv file "temp.csv", which has the below info,
> 
> 
> compName   macAddripAddr
> opSys
> 
> 
> Chris-Dev 0003469F44CC  10.160.24.226   Microsoft
> Windows XP Professional

[snip]

Why are you calling it a Comma Separated Values file when there are no
commas separating values in it?


> am trying to read it in the following way--
> 
> 
> 
 import csv
 infoFile = open ('c:\\temp.csv','r')
 rdr = csv.reader(infoFile)
 for row in rdr:
> 
> 
> ... if row[0] == infnList[0]:
> ... if not row[1] == infnList[1] or not row[2] ==
> infnList[2]:


Should we know what infnList is, or shall we guess?

What does your code do next? 
if condition: (do what?) else: (do what?)

 
> now am comparing my comp Name  with the "compName" fields, and if it
> matches i ll then compare for the "mac address" and "ip address". if
> they are not matching with my system, i have to modify them there
> itself, i mean i have to update "mac address" and "ip address" in the
> same row itself, i dont want to append the information with another row

If I have understood what you are saying, you only need to modify one
single row in the file, the row that matches your personal computer. Why
don't you just open the data file in Notepad or Wordpad, use "Find" to
search for the row you want, and modify it by hand?

If that is not what you need to do, would you like to try explaining what
you need to do a little more carefully? Do you have to modify every line,
or just some? If the data in your temp.csv file is suspect, where are you
getting the good data from?


> to the "temp.csv" file. otherwise it will have two similar computer
> names for two rows, which i dont want to happen.

Why not? Chris-Dev and Kris-Dev are similar but not the same, shouldn't
they get different rows?


Some questions for you to think about:

1. Is the data file small enough to all fit into memory (less than, say,
ten megabytes)?

2. Can you follow this algorithm?

open data file for reading
read everything into a list of strings
close data file
walk the list modifying each string if it needs fixing
open data file for writing
write the list of strings
close data file


3. What about this algorithm?

open data file for reading
open temporary update file for writing
for each record in data file:
is record correct?
yes: write it unchanged to update file
no: fix the record and write it to update file
close data file
close update file
delete obsolete data file
rename update file to data file




-- 
Steven.

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


Re: python coding contest

2005-12-27 Thread Christian Tismer
Remi Villatel wrote:
> Scott David Daniels wrote:
> 
>   [--CUT---]
>>> 39 bytes... 53 bytes... It gives me the impression to follow a jet 
>>> plane with a bike with my 179 bytes!
>   [--CUT--]
> 
>> And I am sadly stuck at 169.  Not even spitting distance from 149 (which
>> sounds like a non-cheat version).
> 
> Try harder!  ;-)  I thought I was stuck at 179 but with a strict diet, I 
> managed to loose some bones  :-D  and get down to a one-liner of 153 bytes.
> 
> No cheating with import but it's so ugly that I'm not sure I will 
> understand my own code next month. And this time I'm sure at 99% that 
> I'm really stuck...

Don't try harder!
Sit back and think of what you're doing,
and what you'd like to do, instead.

And then help me to setup a different contest about content -- chris

-- 
Christian Tismer :^)   
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: - E04 - Leadership! Google, Guido van Rossum, PSF

2005-12-27 Thread Ilias Lazaridis
Robert Hicks wrote:
> Guido has never been, is not, and will not in the future be, a threat
> to Python. End of story.
> 
> Unless of course aliens come into play. You never know.
> 
> Robert

-

TAG.python.evolution.negate.apotheosis.faith

.

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


Re: html resize pics

2005-12-27 Thread rbt
Peter Hansen wrote:
> rbt wrote:
>> What's a good way to resize pictures so that they work well on html 
>> pages? I have large jpg files. I want the original images to remain as 
>> they are, just resize the displayed image in the browser.
> 
> These two things are mutually exclusive by most people's definition of 
> "work well".  You can't push the resizing down to the browser *and* 
> "work well" when working well includes avoiding downloading massive JPGs 
> when only small images are to be shown.
> 
> Can you clarify what you really want? 

Sure, sorry. I use Python to generate html pages. I link to several 
large images at times. I'd like to display a thumbnail image that when 
clicked will go to the original, large jpg for a more detailed view.

  "resize ... image in the browser"
> implies merely using "width" and "height" attributes... 

How does one do that and keep the original ratio intact?

> size of the image *after* the whole thing has been downloaded, in which 
> case this would be solved with mere attributes on the IMG element.
> 
> -Peter
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python coding contest

2005-12-27 Thread Remi Villatel
Scott David Daniels wrote:

[--CUT---]
>> 39 bytes... 53 bytes... It gives me the impression to follow a jet 
>> plane with a bike with my 179 bytes!
[--CUT--]

> And I am sadly stuck at 169.  Not even spitting distance from 149 (which
> sounds like a non-cheat version).

Try harder!  ;-)  I thought I was stuck at 179 but with a strict diet, I 
managed to loose some bones  :-D  and get down to a one-liner of 153 bytes.

No cheating with import but it's so ugly that I'm not sure I will 
understand my own code next month. And this time I'm sure at 99% that 
I'm really stuck...

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


Re: Redirecting both stdout and stderr to the same file

2005-12-27 Thread Kevin Yuan
You should redirecte sys.stderr if you want to log error message.   saveout = sys.stdout   saveerr = sys.stderr   fsock = open('runtime.log', 'w')   sys.stdout
 = sys.stderr = fsock2005/12/28, Randy Kreuziger <[EMAIL PROTECTED]>:




Can stdout and stderr be redirected to the same file?  I would like to redirect both to the same file but I'm not sure how to do it.  Currenting I'm redirectiong stdout using the following code:
   saveout = sys.stdout   fsock = open('runtime.log', 'w')   sys.stdout = fsock
 
The problem is that when en error occurs that my program was not written to handle that error message is being sent to the cmd window and not my log file.  My program may simply need to be more robust however I'm still a python novice.

 
Thanks
 

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

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

Re: html resize pics

2005-12-27 Thread Peter Hansen
rbt wrote:
> What's a good way to resize pictures so that they work well on html 
> pages? I have large jpg files. I want the original images to remain as 
> they are, just resize the displayed image in the browser.

These two things are mutually exclusive by most people's definition of 
"work well".  You can't push the resizing down to the browser *and* 
"work well" when working well includes avoiding downloading massive JPGs 
when only small images are to be shown.

Can you clarify what you really want?  "resize ... image in the browser" 
implies merely using "width" and "height" attributes to override the 
size of the image *after* the whole thing has been downloaded, in which 
case this would be solved with mere attributes on the IMG element.

-Peter

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


Re: python coding contest

2005-12-27 Thread Christian Tismer
James Tanis wrote:
> On 12/25/05, Simon Hengel <[EMAIL PROTECTED]> wrote:
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>>
>>> I'm envisioning lots of convoluted one-liners which
>>> are more suitable to a different P-language... :-)
>> I feel that python is more beautiful and readable, even if you write
>> short programs.

Looking at what I produced the last days, I'm not convinced...

> .. yes but there's a difference, some users of that "other" P-language
> seem to actually take some sort of ritualistic pride in their ability
> to condense code  down to one convoluted line. The language is also a
> little more apt at it since it has a great deal of shorthand built in
> to the core language. Shorter is not necessarily better and I do
> support his opinion that reinforcing short as good isn't really what
> most programmers (who care about readability and quality) want to
> support.

And that's what puzzled me a bit about the approach and the intent
of this contest: Should this evolute into a language war about
goals (shortness, conciseness, brevity, whatnot) that Python
doesn't have as its main targets?
Sure, I see myself hacking this unfortunate little 7-seg code
until it becomes unreadable for me, the trap worked for me,
but why do I do this???

...

> I think code efficiency would be a better choice. A "longer" program
> is only worse if its wasting cycles on badly implemented algorithms.

And we are of course implementing algorithms with a twisted goal-set
in mind: How to express this the shortest way, not elegantly,
just how to shave off one or even two bytes, re-iterating the
possible algorithms again and again, just to find a version that is
lexically shorter? To what a silly, autistic crowd of insane people
do I belong? But it caught me, again!

> Code size is a really bad gauge, If your actually comparing size as in
> byte-to-byte comparison, you'll be getting a ton of implementations
> with absolutely no documentation and plenty of one letter variable
> names. I haven't checked the web site either, are you allowing third
> party modules to be used? If so, that causes even more problems in the
> comparison. How are you going to compare those who use a module vs
> implement it themselves in pure python?

I think it is legal to use any standard pre-installed package you
like, if it belongs to the set of default batteries included.
In a sense, using these tools in a good manner, gives you some
measure about how much the programmer knows about these batteries,
and using them is ok. Actually, I don't see so much applications
for the given problem, but in general, I like the idea to try
many very different approaches to get to a maybe surprizing result.

After all, I'd really love to set up another contest with
different measures and criteria.

One reason btw. might be that I'm not able to win this one, due to
personal blocking. I can't really force myself to go all the
ridiculous paths to save one byte. My keyboard blocks as well.
Maybe I don't consider myself a hacker so much any longer :-)

ciao - chris
-- 
Christian Tismer :^)   
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Rss/xml namespaces sgmllib, sax, minidom

2005-12-27 Thread Sakcee
I want to build a simple validator for rss2 feeds, that checks basic
structure and reports channels , items , and their attributes etc.

I have been reading Mark Pilgrims articles on xml.com, diveintopython
and someother stuff on sgmllib, sax.handlers and content handlers,
xml.dom.minidom

why is all of this necessary, what is the difference between all these
libraries, it seems to me that I can parse the rss2 feed with any of
these libraries.!! ?

what is the difference between namespaces and non-namspaces functions
in sax.handlers.contenthandler , is the namespace defined like domain
names on some website?

thanks for any comments

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


Re: - E04 - Leadership! Google, Guido van Rossum, PSF

2005-12-27 Thread Robert Hicks
Guido has never been, is not, and will not in the future be, a threat
to Python. End of story.

Unless of course aliens come into play. You never know.

Robert

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


Re: - E04 - Leadership! Google, Guido van Rossum, PSF

2005-12-27 Thread Ilias Lazaridis
Harald Armin Massa wrote:
[...] - (comments)

Thank you for your comments.

-

TAG.python.evolution.negate.apotheosis

.

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


Redirecting both stdout and stderr to the same file

2005-12-27 Thread Randy Kreuziger


Can stdout and stderr be redirected to the same file?  I would like to redirect both to the same file but I'm not sure how to do it.  Currenting I'm redirectiong stdout using the following code:
   saveout = sys.stdout   fsock = open('runtime.log', 'w')   sys.stdout = fsock
 
The problem is that when en error occurs that my program was not written to handle that error message is being sent to the cmd window and not my log file.  My program may simply need to be more robust however I'm still a python novice.
 
Thanks
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [EVALUATION] - E04 - Leadership! Google, Guido van Rossum, PSF

2005-12-27 Thread Ilias Lazaridis
Martin P. Hellwig wrote:
> Ilias Lazaridis wrote:
> 
> So I guess you volunteer http://www.python.org/psf/volunteer.html ?

I volunteer and contribute already (with a general validity and python 
specific analysis)

A mediator should communicate the findings and suggestion (after 
verifying them) to the responsibles / community:

http://lazaridis.com/efficiency/process.html#mediator

This would include to pass the relevant ones to the list you've mentioned:

http://www.python.org/psf/volunteer.html

-

TAG.efficiency.process.mediator

.

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


Dr. Dobb's Python-URL! - weekly Python news and links (Dec 27)

2005-12-27 Thread Cameron Laird
QOTW:  "My wild-ass guess is that, same as most other Open Source
communities, we average about one asshole per member." - Tim Peters
http://groups.google.com/group/comp.lang.python/msg/02236cc5ab54fd90?hl=en

"[T]he only fundamentally new concept that has been added since Python
1.5.2 is generators.  And a lot of the stuff you want generators for
can be emulated with sequences and extra buffer layers." - Fredrik Lundh


gene tani and Olivier Grisel collect information about memory- and
time-profiling:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6186ae64a564ad5a/

Python builds in a convenience for, "this segment of
code isn't finished."

http://groups.google.com/group/comp.lang.python/browse_thread/thread/3179dcce33a33fbb/

You want to constrain the time allowed to a particular
Python function to execute.  A reasonably standard solution
is available.  To limit *two* potentially concurrent functions,
though ... well, that's not a strength of Python:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/bd808b80fc8191/

Contest your Python coding:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ac7fdb93af4e0b2f/

Sorting depends on comparisons.  It is NOT possible, in 
general, to memoize these comparisons, in the sense that
the Python run-time library should take on the responsibility
for developers.  DSU and other situation-specific strategies
always remains available, of course:
http://groups.google.com/group/comp.lang.python/msg/8007c9d7fabe6223

http://groups.google.com/group/comp.lang.python/browse_thread/thread/773d64e6d8b77802/

Yes, Guido's at Google.  He'll work on and with Python.
How much more "official" do you need it to be?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/32dc95bd671542f3/

Peter Hansen and David Wahler lucidly explain how hard it
is to keep even a little security.  A digital datum in any
one useful place is likely to leak all over, even for a
problem as seemingly simple as protection of a password
used for cron-automated access:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b8bdb21a084d6a99/

Is it "humane" that Ruby typically abbreviates "get(end)"
as "last"?  Dave Benjamin and Kent Johnson discuss the 
matter seriously and usefully (with examples!):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d2ada62cd187dd65/



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.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

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

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon 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/

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. 
  

Re: [EVALUATION] - E04 - Leadership! Google, Guido van Rossum, PSF

2005-12-27 Thread Ilias Lazaridis
Michael wrote:
> Ilias Lazaridis wrote:
> 
>>[ panic, fear, worry ]
> 
> What's wrong with just saying "Congratulations!" ? 

nothing.

But enouth people do this.

I am focusing on weaknesses & threats:

http://lazaridis.com/efficiency/graph/analysis.html

> First thing I thought was
> "ooh, maybe Guido will be able to work on P3K there" - after all that would
> benefit Google *and* everyone else :-)

My main intrest is to see python pass this simple evaluation (currently 
it fails):

http://lazaridis.com/case/lang/python.html

> (Especially if he uses PyPy to experiment and play in ... :)
> 
> Merry Christmas/Happy New Year :-)
> 
> Michael.

.

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


Re: Microsoft's JavaScript doc's newfangled problem

2005-12-27 Thread dimitri pater
On the other hand, in terms of documentation quality, technologicalexcellence, responsibility in software, Microsoft in the 21st century
is the holder of human progress when compared to the motherfucking OpenSourcers lying thru their teeth fuckheads. XahThis is not amusing anymore, somebody please stop this guy from posting here. Attention is what he wants, but I can't help replying to this egocentric nonsense, silly me.
Dimitri
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python coding contest

2005-12-27 Thread Tim Hochberg
Jean-Paul Calderone wrote:
> On Tue, 27 Dec 2005 14:02:57 -0700, Tim Hochberg <[EMAIL PROTECTED]> wrote:
> 
>>Shane Hathaway wrote:
>>
>>>Paul McGuire wrote:
>>>
>>>
>>>Also, here's another cheat version.  (No, 7seg.com does not exist.)
>>>
>>>   import urllib2
>>>   def seven_seg(x):return urllib2.urlopen('http://7seg.com/'+x).read()
>>>
>>
>>And another one from me as well.
>>
>>class a:
>> def __eq__(s,o):return 1
>>seven_seg=lambda i:a()
>>
> 
> 
> This is shorter as "__eq__=lambda s,o:1".
> 
> But I can't find the first post in this thread... What are you 
> guys talking about?

There's a contest described at http://www.pycontest.net/. People have 
been working on two sorts of solutions: 'honest' solutions that actually 
do what's described there. The best of these are around 130 characters. 
There's also a set of 'cheat' solutions that fool the supplied test 
program. I suspect that these will not pass muster when they actually 
get submitted, but we'll see I suppose. A couple of people have figured 
out how to write these cheating solution extremely compactly (32 bytes). 
One of the simpler ones is:

import test;seven_seg=test.test_vectors.get

This will make sense if you look at the kit supplied by the above site.

-tim

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


csv file how to modify the row

2005-12-27 Thread muttu2244
Hi everybody


Am trying to read a csv file "temp.csv", which has the below info,


compName   macAddripAddr
opSys


Chris-Dev 0003469F44CC  10.160.24.226   Microsoft
Windows XP
Professional
Shivayogi-Dev  000D5234F44C 10.160.24.136   Microsoft Windows XP
Professional
John-test 000D123F44CC  10.160.24.216   Microsoft
Windows XP
Professional Steve-Dev000D123F55CC  10.160.24.116
Microsoft
Windows XP Professional


am trying to read it in the following way--



>>> import csv
>>> infoFile = open ('c:\\temp.csv','r')
>>> rdr = csv.reader(infoFile)
>>> for row in rdr:


... if row[0] == infnList[0]:
... if not row[1] == infnList[1] or not row[2] ==
infnList[2]:

now am comparing my comp Name  with the "compName" fields, and if it
matches i ll then compare for the "mac address" and "ip address". if
they are not matching with my system, i have to modify them there
itself, i mean i have to update "mac address" and "ip address" in the
same row itself, i dont want to append the information with another row

to the "temp.csv" file. otherwise it will have two similar computer
names for two rows, which i dont want to happen.


please give me the ways how i can work on this.


thanks in advance 
yogi

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


Re: how to modify the csv file

2005-12-27 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> i really tried with csv module, but i dint get anything,

http://www.catb.org/~esr/faqs/smart-questions.html#beprecise

> could u plase tell me the method to modify a particular row, or
> atleast let me know how can i delete a row in a csv file.

the same way as you'd modify or delete a row in any other text
file: by reading the entire file, modifying the data, and writing it
out again.

you can either do this line by line (reading from one file and writing
to another, modifying the data on the way), or in "bulk" (load every-
thing into memory, modify the data structure, and write it out again).





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


Re: python coding contest

2005-12-27 Thread Justin Azoff
Tim Hochberg wrote:
> Note that in principle it's possible to encode the data for how to
> display a digit in one byte. Thus it's at least theoretically possible
> to condense all of the information about the string into a string that's
> 10 bytes long. In practice it turns out to be hard to do that, since a
> 10 byte string will generally have a representation that is longer than
> 10 bytes because of the way the escape sequences get printed out. As a
> result various people seem to be encoding the data in long integers of
> one sort or another. The data is then extracted using some recipe
> involving shifts and &s.
>
> -tim

I have a 163 character version(on 8 lines, haven't tried to compress it
further) that does something like that.. the string ended up being
printable enough to be included in the source unescaped.

I think for most approaches, any space you save by using a string you
lose after quoting it and using ord() to turn a character back into a
number.

I'm sure this particular method is a dead end, but it is a very
intersting and probably unique  solution :-)

-- 
- Justin

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


html resize pics

2005-12-27 Thread rbt
What's a good way to resize pictures so that they work well on html 
pages? I have large jpg files. I want the original images to remain as 
they are, just resize the displayed image in the browser.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to modify the csv file

2005-12-27 Thread muttu2244
hi skip
i really tried with csv module, but i dint get anything, could u plase
tell me the method to modify a particular row, or atleast let me know
how can i delete a row in a csv file.

thanks 
yogi

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


Re: PyHtmlGUI Project is looking for developers

2005-12-27 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
> the idea of pyhtmlgui is that you can develop a web application the
> same way like a standard gui application. So what you get is a
> widget tree (buttons, forms, title bars, etc.) on the server side
> and a gui on the client side.

Ah, okay - it's the other way around than what I thought ;-)

I would love to be able to create an app using a real GUI toolkit, and
then transparently be able to create it online.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python coding contest

2005-12-27 Thread Claudio Grondi
[EMAIL PROTECTED] wrote:
> I now have a version which passes the test suite in 32 bytes  grin>
> 
> -T.
> 
After I have posted the statement, that I have one with 39 bytes, I had 
the 32 version five minutes later, but thougt that instead of posting it 
I can maybe use it as entry on the contest ... Now this hope is over and 
as the 32 bytes are the lowest possible limit I can currently think of 
the dream of winning the contest seems to be over.

Anyone below 32 bytes?

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


Re: Microsoft's JavaScript doc's newfangled problem

2005-12-27 Thread Xah Lee
> What did you expect?

There are two interpretations to this Microsoft's JavaScript doc
problem:

1. They didn't do it intentionally.

2. They did it intentionally.

If (1), then it would be a fucking incompetence of inordinate order. If
(2), they would be assholes, even though they have the right to do so.

On the other hand, in terms of documentation quality, technological
excellence, responsibility in software, Microsoft in the 21st century
is the holder of human progress when compared to the motherfucking Open
Sourcers lying thru their teeth fuckheads.

 Xah
 [EMAIL PROTECTED]
 ∑ http://xahlee.org/


--
Xah Lee wrote:

sometimes in the last few months, apparently Microsoft made changes to
their JavaScript documentation website:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/scri...


so that, one has to goddamn press the "expand" button to view the
documentation, for every goddamn page.

What the fuck is going on?

And, good url before the change are now broken (giving HTTP error 404).

Many of the newfangled buttons such as "Copy Code" doesn't goddamn work

in Safari, FireFox, iCab, Mac IE.

And, in any of these browsers, the code examples becomes single
congested block without any line breaks. e.g.

«Circle.prototype.pi = Math.PI; function ACirclesArea () { return
this.pi * this.r * this.r; // The formula for the area of a circle is
r2. } Circle.prototype.area = ACirclesArea; // The function
that calculates the area of a circle is now a method of the Circle
Prototype object. var a = ACircle.area(); // This is how you would
invoke the area function on a Circle object.»

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

Re: python coding contest

2005-12-27 Thread Jean-Paul Calderone
On Tue, 27 Dec 2005 14:02:57 -0700, Tim Hochberg <[EMAIL PROTECTED]> wrote:
>Shane Hathaway wrote:
>> Paul McGuire wrote:
>>
>>
>> Also, here's another cheat version.  (No, 7seg.com does not exist.)
>>
>>import urllib2
>>def seven_seg(x):return urllib2.urlopen('http://7seg.com/'+x).read()
>>
>And another one from me as well.
>
>class a:
>  def __eq__(s,o):return 1
>seven_seg=lambda i:a()
>

This is shorter as "__eq__=lambda s,o:1".

But I can't find the first post in this thread... What are you 
guys talking about?

Jean-Paul

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


Re: python coding contest

2005-12-27 Thread Duncan Booth
Tim Hochberg wrote:

> py pan wrote:
>> When you guys say 127~150 characters, did you guys mean
>> usinging test_vectors.py in some way? Or there's no import at all?
>> 
> 
> No import at all. The shortest solution reported so far is 131 
> characters. Getting down to 127 is just a guess as to where the lower 
> bound is likely to be.

Sorry about the 131, I had a spurious whitespace character so it should 
have been 130.

> The data is then extracted using some recipe 
> involving shifts and &s.

My 130 character solution has a shift and an &. My 133 character solution 
didn't. I feel sure that 130 isn't the limit, my guess would be that 127 or 
128 ought to be possible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyHtmlGUI Project is looking for developers

2005-12-27 Thread phoenixathell
Hi Marco,

that is one of our goals. But so far we didn't had the time to do it.

PyHtmlGUI is already complete independent from Zope but it still needs
some kind of request handling (another small script). One of our next
steps will be to create a abstraction of the request handling to be
independent of the web server. 

Ingo

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


Re: Qtdesigner and python

2005-12-27 Thread [EMAIL PROTECTED]
u can use`pyuic`  for this ..

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


Re: python coding contest

2005-12-27 Thread Tim Hochberg
Shane Hathaway wrote:
> Paul McGuire wrote:
> 
>>"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
>>news:[EMAIL PROTECTED]
>>
>>
>>>Well *I'm* certainly looking forward to learning some new tricks!  My
>>>(non-cheat) version is a comparatively-portly 245, and no alternatives are
>>>popping into my head at the moment!
>>>
>>>-- Paul
>>>
>>>
>>
>>down to 2 lines, 229 characters
> 
> 
> I'm down to 133 characters (counted according to 'wc -c') on a single 
> line.  It contains about 11 whitespace characters (depending on what you 
> consider whitespace.)  It's way too tricky for my taste, but it's fun to 
> play anyway.  Has anyone done better so far?  Here's a hint on my 
> strategy: the code contains three large integers. :-)

I see now how three large integers could be useful, but the best I could 
do with that is 136 characters on 1-line. Yesterday that would have been 
great, but it's not so hot today.

> 
> Also, here's another cheat version.  (No, 7seg.com does not exist.)
> 
>import urllib2
>def seven_seg(x):return urllib2.urlopen('http://7seg.com/'+x).read()
> 
And another one from me as well.

class a:
  def __eq__(s,o):return 1
seven_seg=lambda i:a()

-tim

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


Re: PHP = Perl Improved

2005-12-27 Thread Xah Lee
«use bytes;  # Larry can take Unicode and shove it up his ass
sideways.
# Perl 5.8.0 causes us to start getting incomprehensible
# errors about UTF-8 all over the place without this.»

From: the source code of WebCollage (1998)
http://www.jwz.org/webcollage/
by Jamie W. Zawinski (~1971-)

The code is 3.4 thousand lines of Perl in one single file. Rather
incomprehensible.

 Xah
 [EMAIL PROTECTED]
 ∑ http://xahlee.org/

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

Re: how to modify the csv file

2005-12-27 Thread skip

yogi> now if i got to modify one particular line from these three rows,
yogi> how can i do that. 

Check out the csv module.

Skip


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


how to modify the csv file

2005-12-27 Thread muttu2244
hi everybody
am trying to modify a particular string from a csv file.

for ex

say i have

 compName,   ipAddr,   MacAddr,Os

  sdfsdf   ,129.122.12.34  , dsfiasdf, wsfdjhs
  hsdfdf  ,  123.234.34.34, dsfiasdfds, wewr

etc

now if i got to modify one particular line from these three rows , how
can i do that.

thanks in advance
yogi

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


Re: python coding contest

2005-12-27 Thread Tim Hochberg
py pan wrote:
> When you guys say 127~150 characters, did you guys mean
> usinging test_vectors.py in some way? Or there's no import at all?
> 

No import at all. The shortest solution reported so far is 131 
characters. Getting down to 127 is just a guess as to where the lower 
bound is likely to be.

Note that in principle it's possible to encode the data for how to 
display a digit in one byte. Thus it's at least theoretically possible 
to condense all of the information about the string into a string that's 
10 bytes long. In practice it turns out to be hard to do that, since a 
10 byte string will generally have a representation that is longer than 
10 bytes because of the way the escape sequences get printed out. As a 
result various people seem to be encoding the data in long integers of 
one sort or another. The data is then extracted using some recipe 
involving shifts and &s.

-tim

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


Re: Beautiful Python

2005-12-27 Thread Peter Decker
On 27 Dec 2005 10:02:17 -0800, Gekitsuu <[EMAIL PROTECTED]> wrote:
> My
> hypothetical situation was as follows. I'm writing a new generic SQL
> module and I want to make it so I only call the appropriate module for
> the type of SQL server I'm talking to. Then it would make sense to
> load, for instance, the mysql module and not the sqlite, postgresql,
> etc.

You should take a look at the Dabo project. The dabo.db module take a
setting and imports just the required library for the chosen database.
It really isn't that difficult a concept to handle.

--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python coding contest

2005-12-27 Thread James Tanis
On 12/25/05, Simon Hengel <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> > I'm envisioning lots of convoluted one-liners which
> > are more suitable to a different P-language... :-)
> I feel that python is more beautiful and readable, even if you write
> short programs.

.. yes but there's a difference, some users of that "other" P-language
seem to actually take some sort of ritualistic pride in their ability
to condense code  down to one convoluted line. The language is also a
little more apt at it since it has a great deal of shorthand built in
to the core language. Shorter is not necessarily better and I do
support his opinion that reinforcing short as good isn't really what
most programmers (who care about readability and quality) want to
support.
>
> > How about """best compromize between shortness and readibility
> > plus elegance of design"""?
> I would love to choose those criteria for future events. But I'm not
> aware of any algorithm that is capable of creating a ranking upon them.
> Maybe we can come up with a solution. Any ideas?
>
I think code efficiency would be a better choice. A "longer" program
is only worse if its wasting cycles on badly implemented algorithms.
Code size is a really bad gauge, If your actually comparing size as in
byte-to-byte comparison, you'll be getting a ton of implementations
with absolutely no documentation and plenty of one letter variable
names. I haven't checked the web site either, are you allowing third
party modules to be used? If so, that causes even more problems in the
comparison. How are you going to compare those who use a module vs
implement it themselves in pure python?

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


Re: python coding contest

2005-12-27 Thread py pan
When you guys say 127~150 characters, did you guys mean usinging test_vectors.py in some way? Or there's no import at all?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python coding contest

2005-12-27 Thread Guyon Morée
So, is an ugly short one a candidate?

i managed in 199 bytes :)

i'll send it in anyway

ciao

http://gumuz.looze.net/

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


Re: Beautiful Python

2005-12-27 Thread Fredrik Lundh
"Gekitsuu" wrote:

> That is part of what I was asking but I was also hoping to hear the
> common wisdom so to speak. When I posted I had considered the idea for
> a bit and the situations people have mentioned were similar to the
> scenario I came up with as a good time to break such a rule. My
> hypothetical situation was as follows. I'm writing a new generic SQL
> module and I want to make it so I only call the appropriate module for
> the type of SQL server I'm talking to. Then it would make sense to
> load, for instance, the mysql module and not the sqlite, postgresql,
> etc. But should it be part of the PEP to include what to do in a
> situation were it makes sense to break the rule? Something like if an
> import needs to be in a location other than the top of the module
> because of conditions determining if it will be loaded, there should be
> a comment at the top of the module where the other imports are declared
> stating what is loaded, why it is elsewhere, and a general idea of
> where it is. Something like..
>
> # import mysql_module
> # This is imported in the useMysql() function and is only imported if
> needed
>
> I looked for a way to make a suggestion to the PEP but it wasn't
> obvious to me from the link how you'd do it.

the PEP has enough silly rules as it is; no need to add even more
sillyness.

(why would anyone interested in what your useMysql function is doing
waste any time reading comments at the top of the file ?  you're over-
doing things.  don't do that; that's not pythonic)





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


Re: MySQLdb Python API: Unable to connect

2005-12-27 Thread Fredrik Lundh
Dennis Lee Bieber wrote:

> > I don't see anything with 324 in there ? What do you mean ?
> >
> A direct copy from about ten lines above.
>
> > >c=MySQLdb.Connect(host='localhost',user='root',passwd='',db='shop',port=330­6)
>
> 330 minus 6 equals 324

except that the - you're seeing is a soft hyphen, so most people won't
see it...

here's an excerpt from the message source:

> >>> c=3DMySQLdb.Connect(host=3D'localhost',user=3D'root',passwd=3D'',db=
=3D'shop',port=3D330=AD6)

=3D is an equal sign
=AD is a soft hyphen





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

Re: SyntaxError: invalid syntax

2005-12-27 Thread Terry Hancock
On Tue, 27 Dec 2005 09:32:18 GMT
"DIBS" <[EMAIL PROTECTED]> wrote:
> >>> python sudoku.py
> File "", line 1
>python sudoku.py
> ^
> 
> >>>SyntaxError: invalid syntax
> 
> Thanks for your help.
> The above is the extact message.

Based on the ">>>" prompt, I'd say you tried to type this
into the python interactive interpreter. It's supposed to be
a shell command -- i.e. you *invoke* the python interpreter
to run the file from the command line.

If you are already running python, then you might get what
you want by importing the module:

>>> import sudoku

but whether that's what you really want or not depends on
how the module is meant to be used (is it a "module" or a
"script"?).

Cheers,
Terry

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: Beautiful Python

2005-12-27 Thread Gekitsuu
That is part of what I was asking but I was also hoping to hear the
common wisdom so to speak. When I posted I had considered the idea for
a bit and the situations people have mentioned were similar to the
scenario I came up with as a good time to break such a rule. My
hypothetical situation was as follows. I'm writing a new generic SQL
module and I want to make it so I only call the appropriate module for
the type of SQL server I'm talking to. Then it would make sense to
load, for instance, the mysql module and not the sqlite, postgresql,
etc. But should it be part of the PEP to include what to do in a
situation were it makes sense to break the rule? Something like if an
import needs to be in a location other than the top of the module
because of conditions determining if it will be loaded, there should be
a comment at the top of the module where the other imports are declared
stating what is loaded, why it is elsewhere, and a general idea of
where it is. Something like..

# import mysql_module
# This is imported in the useMysql() function and is only imported if
needed

I looked for a way to make a suggestion to the PEP but it wasn't
obvious to me from the link how you'd do it.

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


Re: python coding contest

2005-12-27 Thread Tim Hochberg
Shane Hathaway wrote:
> Tim Hochberg wrote:
> 
>>Paul McGuire wrote:
>>
>>
>>>"Shane Hathaway" <[EMAIL PROTECTED]> wrote in message
>>>news:[EMAIL PROTECTED]
>>>
>>>
>>>
I'm down to 133 characters (counted according to 'wc -c') on a single
line.  It contains about 11 whitespace characters (depending on what you
consider whitespace.)  It's way too tricky for my taste, but it's fun to
play anyway.  Has anyone done better so far?  Here's a hint on my
strategy: the code contains three large integers. :-)

>>>
>>>With 1 large integer, I am down to 200 characters on 1 multiline line.  I
>>>can guess why you have 3 integers vs. 1, but I don't see how that saves you
>>>any characters of code.
>>
>>
>>This is interesting. I have a six line solution that is 133 characters 
>>long.
> 
> 
> 133 characters according to 'wc -c'? 

Indeed:

C:\...\pycontest_01>wc -c seven_seg_8.py
 133 seven_seg_8.py

I you strip leading and trailing whitespace, it's 122 characters. For 
comparison, seven_seg_1.py is 816 characters long:)

> If so, that will surely win style 
> points over my one-line monster.  

It's pretty readable, at least with the right tabs setting in one's 
editor, except for the guts of the thing, which consists of 21 
characters of marvelously inscrutable goop.

> But I bet someone's going to do better 
> (without cheating.)

I expect so. However, most people, at least those that are talking, seem 
to be stalling out in the low 130s, so I predict the final winner will 
be 127-130 characters long.

-tim

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


Re: Qtdesigner and python

2005-12-27 Thread Phil Thompson
On Tuesday 27 December 2005 5:10 pm, Siraj Kutlusan wrote:
> I heard that you can use .ui files with python or something of the likes.
> Could anyone help me with telling me how to do this?

You can either convert the .ui file to Python code using pyuic or you can load 
the .ui file directly using the QWidgetFactory class.

Normally people use pyuic because they want to sub-class from the class 
created by Designer to add application logic.

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


Re: python coding contest

2005-12-27 Thread Duncan Booth
Tim Hochberg wrote:
> This is interesting. I have a six line solution that is 133 characters
> long. I use no long integers, which is what's interesting; two
> distinct solutions with the same length. I played with long integers
> for a bit, and I can see how one could use a single long integer, but
> no idea how one would use three.
> 
I have a 131 character solution with 3 large numbers. Once you've figured 
out how to use 3 numbers there's actually quite a variety of options to use 
different numbers in subtly different ways: I was stuck on 133 characters 
for quite a while, but I think the trick is to think of ways to make the 
numbers smaller.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: closing stdin, stdout and stderr

2005-12-27 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 Martijn Brouwer <[EMAIL PROTECTED]> wrote:
...
> I read this one, which was the reason that I tried os.close instead of
> sys.stdXXX.close(). But I would like to know why it does not close a
> file discriptor is I call its close method().

They're special.  I suppose because of internal dependencies - last
chance exception handler etc. - they are created without a close
function, internally, so close() has no effect.   I don't know if it
really makes any sense, since anyway one may close the file descriptors
directly as you did.

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


Re: help with lists and writing to file in correct order

2005-12-27 Thread Siraj Kutlusan
Why don't you use pickle instead of directly writing to the file yourself?


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


Qtdesigner and python

2005-12-27 Thread Siraj Kutlusan
I heard that you can use .ui files with python or something of the likes.
Could anyone help me with telling me how to do this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python coding contest

2005-12-27 Thread Shane Hathaway
Tim Hochberg wrote:
> Paul McGuire wrote:
> 
>>"Shane Hathaway" <[EMAIL PROTECTED]> wrote in message
>>news:[EMAIL PROTECTED]
>>
>>
>>>I'm down to 133 characters (counted according to 'wc -c') on a single
>>>line.  It contains about 11 whitespace characters (depending on what you
>>>consider whitespace.)  It's way too tricky for my taste, but it's fun to
>>>play anyway.  Has anyone done better so far?  Here's a hint on my
>>>strategy: the code contains three large integers. :-)
>>>
>>
>>With 1 large integer, I am down to 200 characters on 1 multiline line.  I
>>can guess why you have 3 integers vs. 1, but I don't see how that saves you
>>any characters of code.
> 
> 
> This is interesting. I have a six line solution that is 133 characters 
> long.

133 characters according to 'wc -c'?  If so, that will surely win style 
points over my one-line monster.  But I bet someone's going to do better 
(without cheating.)

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


Re: oop in python

2005-12-27 Thread Steven D'Aprano
On Tue, 27 Dec 2005 02:42:18 -0800, novice wrote:

> 
> hello over there!
> I have the following question:
> Suppose I created a class:   class Point:
>   pass
> then instanciated an instance:  new = Point()
> So now how to get the instance new as a string: like ' new '   ;

'new' is not a instance object, it is a name which happens to be bound to
an instance object.

new = Point()  # bind 'new' to an instance
new = 12  # now bind to an int
new = float(new)  # and now bind to a float
del new  # delete the name 'new'
new = "Spanish Inquisition"  # bind 'new' to a string

Names can be bound to any object, but objects can't tell what name (or
names!) they are bound to.

foo = bar = Point()
# both 'foo' and 'bar' are bound to the same instance

> Is there any built in function or method
>  for eg:
> 
> class Point:
>def _func_that_we_want_(self):
>   return ...
> new._func_that_we_want_()  --->  ' new '

This is generally impossible, and here is why:

foo = Point()  # create an instance of Point and bind it to the name 'foo'
bar = foo  # 'bar' also is bound to the same instance 
parrot = spam = eggs = bar
# we have five names bound to the _same_ instance (NOT five copies)
del foo  # now we have only four

If there was a method "_func_that_we_want_" that returns the name of the
instance, what should it return? bar, parrot, spam or eggs?

Objects can't tell what names they are bound to.

If you tell us what you hoped to do with the name once you had it, perhaps
we can suggest something else.


-- 
Steven.

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


Re: I want to exclude an expression of a sequence of charecters with regex

2005-12-27 Thread Fredrik Lundh
"28tommy" wrote:

> I know how to exclude 1 charecter from a compiled sequence of the re
> module- '[^a]', but if I want to exclude a word or a sequence as one
> unit (not as separate charecters) to be checked how do I do that?
>
> I tried re.compile('[^(abc)]')
> ... or re.compile('[^a][^b][^c]')
> ... or re.compile('[^a^b^c]')
> None of these worked.

look for "negative lookahead assertion" on this page:

http://docs.python.org/lib/re-syntax.html





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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-27 Thread Pierre Quentel
Yes, there is a clear winner : "python zope" = 3.950.000

Pierre

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


Re: PyHtmlGUI Project is looking for developers

2005-12-27 Thread phoenixathell
Hi Sybren,

the idea of pyhtmlgui is that you can develop a web application the
same way like a standard gui application. So what you get is a widget
tree (buttons, forms, title bars, etc.) on the server side and a gui on
the client side. The server in our case would be something like Apache
or Zope webserver (in fact at the moment we only support Zope, but we
want to extend it to Apache as well). The client is a browser. So the
whole application is design as a thin-client-fat-server architecture.

KHTML is just a rendering engine like IE or gecko that renders incoming
html/css pages. That means that you need a plattform dependened program
where you embedd KHTML control. But than you are limited to a plattform
and you will have trouble to port the program to other systems. And the
biggest point is that the program is executed on the clients machine
whereas in our case the program is executed on the server and only the
htmlgui is delivered to the client.

Our dream is that established web applications like phpmyadmin or
squirrelmail will get a interface that can be recognized between
different applications. Through this approach you can expect that the
behaviour will be the same. That was pretty much the same idea behind
KDE or even more evil Windows.

So far every web application project used its own interface because
there is no common framework. What we see now is a growing development
of content managment systems. But these frameworks are limited to the
task of content managment. We propose a more general view of web
applications. 


I hope that answers your question.

Greetings,
Ingo

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


Re: [EVALUATION] - E04 - Leadership! Google, Guido van Rossum, PSF

2005-12-27 Thread Michael
Ilias Lazaridis wrote:
> [ panic, fear, worry ]

What's wrong with just saying "Congratulations!" ? First thing I thought was
"ooh, maybe Guido will be able to work on P3K there" - after all that would
benefit Google *and* everyone else :-)

(Especially if he uses PyPy to experiment and play in ... :)

Merry Christmas/Happy New Year :-)


Michael.

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


Re: python coding contest

2005-12-27 Thread Tim Hochberg
Paul McGuire wrote:
> "Shane Hathaway" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> 
>>I'm down to 133 characters (counted according to 'wc -c') on a single
>>line.  It contains about 11 whitespace characters (depending on what you
>>consider whitespace.)  It's way too tricky for my taste, but it's fun to
>>play anyway.  Has anyone done better so far?  Here's a hint on my
>>strategy: the code contains three large integers. :-)
>>
> 
> With 1 large integer, I am down to 200 characters on 1 multiline line.  I
> can guess why you have 3 integers vs. 1, but I don't see how that saves you
> any characters of code.

This is interesting. I have a six line solution that is 133 characters 
long. I use no long integers, which is what's interesting; two distinct 
solutions with the same length. I played with long integers for a bit, 
and I can see how one could use a single long integer, but no idea how 
one would use three.


-tim

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


Re: PyHtmlGUI Project is looking for developers

2005-12-27 Thread Marco Aschwanden
A good idea... but I would prefer it being abstracted from Zope...


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


Re: libxml2dom problems

2005-12-27 Thread Fredrik Lundh
"ankit" <[EMAIL PROTECTED]> wrote:

>I am using libxml2dom but having problem when parsing. It gives me the
> following error:
>
> File "exlibxml2dom.py", line 4, in ?
>document = libxml2dom.parse("moc.xml")
>  File "/usr/lib/python2.2/site-packages/libxml2dom/__init__.py", line
> 472, in parse
>return parseFile(stream_or_string, html)
>  File "/usr/lib/python2.2/site-packages/libxml2dom/__init__.py", line
> 484, in parseFile
>return Document(Node_parseFile(filename, html))
>  File
> "/usr/lib/python2.2/site-packages/libxml2dom/macrolib/macrolib.py",
> line 431, in parseFile
>libxml2mod.xmlCtxtUseOptions(context, XML_PARSE_NOERROR |
> XML_PARSE_NOWARNING | XML_PARSE_NONET)
> AttributeError: 'module' object has no attribute 'xmlCtxtUseOptions'
>
> LET me know what is the problem with this ...

I'm not sure posting the same question over and over and over again is really
the best way to get help.  I recommend waiting at least 24 hours, and making
sure that you add more information to each followup message.

But alright, I guess I can guess: the error message says that the libxml2mod
module doesn't have a xmlCtxtUseOptions function.  Two seconds with google
indicates that this is a libxml2 function that was added in 2.6.X.  If it's not 
avail-
able in your install, chances are that you're using an outdated version of 
libxml2
(or an old version of the Python bindings).

 



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


libxml2dom problems

2005-12-27 Thread ankit
I am using libxml2dom but having problem when parsing. It gives me the
following error:

 File "exlibxml2dom.py", line 4, in ?
document = libxml2dom.parse("moc.xml")
  File "/usr/lib/python2.2/site-packages/libxml2dom/__init__.py", line
472, in parse
return parseFile(stream_or_string, html)
  File "/usr/lib/python2.2/site-packages/libxml2dom/__init__.py", line
484, in parseFile
return Document(Node_parseFile(filename, html))
  File
"/usr/lib/python2.2/site-packages/libxml2dom/macrolib/macrolib.py",
line 431, in parseFile
libxml2mod.xmlCtxtUseOptions(context, XML_PARSE_NOERROR |
XML_PARSE_NOWARNING | XML_PARSE_NONET)
AttributeError: 'module' object has no attribute 'xmlCtxtUseOptions'


LET me know what is the problem with this ...

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


Patch : doct.merge

2005-12-27 Thread Nicolas Lehuen
Hi,

I've posted this patch on Source forge :

http://sourceforge.net/tracker/index.php?func=detail&aid=1391204&group_id=5470&atid=305470

If you want to update a dictionary with another one, you can simply use
update :

a = dict(a=1,c=3)
b = dict(a=0,b=2)
a.update(b)
assert a == dict(a=0,b=2,c=3)

However, sometimes you want to merge the second dict into the first,
all while keeping the values that are already defined in the first.
This is useful if you want to insert default values in the dictionary
without overriding what is already defined.

Currently this can be done in a few different ways, but all are awkward
and/or inefficient :

a = dict(a=1,c=3)
b = dict(a=0,b=2)

Method 1:
for k in b:
if k not in a:
a[k] = b[k]

Method 2:
temp = dict(b)
temp.update(a)
a = temp

This patch adds a merge() method to the dict object, with the same
signature and usage as the update() method. Under the hood, it simply
uses PyDict_Merge() with the override parameter set to 0 instead of 1.
There's nothing new, therefore : the C API already provides this
functionality (though it is not used in the dictobject.c scope), so why
not expose it ? The result is :

a = dict(a=1,c=3)
b = dict(a=0,b=2)
a.merge(b)
assert a == dict(a=1,b=2,c=3)

Does this seem a good idea to you guys ?

Regards,
Nicolas

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


I want to exclude an expression of a sequence of charecters with regex

2005-12-27 Thread 28tommy
Hello all,

I know how to exclude 1 charecter from a compiled sequence of the re
module- '[^a]', but if I want to exclude a word or a sequence as one
unit (not as separate charecters) to be checked how do I do that?

I tried re.compile('[^(abc)]')
... or re.compile('[^a][^b][^c]')
... or re.compile('[^a^b^c]')
None of these worked.

Thanks in advance  (-:

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


Re: oop in python

2005-12-27 Thread Uwe Hoffmann
novice schrieb:

> class Point:
>def _func_that_we_want_(self):
>   return ...


return self.__class__.__name__

http://docs.python.org/ref/types.html#l2h-109
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python coding contest

2005-12-27 Thread ZeD
Ciao, Shane Hathaway! Che stavi dicendo?

> I'm down to 133 characters (counted according to 'wc -c') on a single
> line.  It contains about 11 whitespace characters (depending on what you
> consider whitespace.)

$ wc -c seven_seg.py
137 seven_seg.py
$ sed 's/ //g' seven_seg.py|wc -c
120
(yeah, too much spaces, I think)

> It's way too tricky for my taste, but it's fun to 
> play anyway.  Has anyone done better so far?  Here's a hint on my
> strategy: the code contains three large integers. :-)

why using 3 longint is better than one?! Trying to "split" my BIG int in 3
just make my code longer...

ok, ok... I will wait the end of the contest... :)

-- 
Firma in costruzione

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


Re: Windows and python execution

2005-12-27 Thread Daniel Dittmar
Tim Roberts wrote:
> Mark Carter <[EMAIL PROTECTED]> wrote:
>>What you need to do is include the following line in autoexec.bat:
>>set .py=c:\python24\python.exe
>>
>>This will achieve the desired result. I'm suprised more people don't use it.
> 
> 
> They don't use it, because it doesn't do anything.  I'd be interested to
> know where you read that.

This is a feature of 4NT, a commercial replacement for cmd.exe. And 
unlike cmd.exe, it even allows redirection of stdin/stdout when a script 
is executed through the extension (the OP's next post is probably going 
to be 'why doesn't redirection work?').

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


Re: how to convert string like '\u5927' to unicode string u'\u5927'

2005-12-27 Thread Ganesan Rajagopal
> "Fredrik" == Fredrik Lundh <[EMAIL PROTECTED]> writes:

> Ganesan Rajagopal wrote:
>>> unicodeStrFromNetwork = '\u5927'
>>> unicodeStrNative = _unicodeRe(unisub, unicodeStrFromNetwork)
>> 
>> How about unicodeStrNative = eval("u'%s'" % (unicodeStrFromNetwork,))

> unicodeStrFromNetwork = "' + str(__import__('os').system('really bad idea')) 
> + '"

Thanks for the warning. I should really know better! *blush* 

Ganesan

-- 
Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA
Web: http://employees.org/~rganesan| http://rganesan.blogspot.com


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


Re: PyHtmlGUI Project is looking for developers

2005-12-27 Thread phoenixathell
Because embedding KHTML means that you have a GUI application that runs
on a special operation system.

But what we propose is that you can write a web application in the same
way like your GUI application and it appears like a "normal" GUI. Web
application means in these case that you have a application that has a
browser as a frontend client. The idea itself is a little bit like XUL
for mozilla. But there you are dependent to the mozilla browser.

Our main goal is plattform independence. Because our user are using os
x, linux and windows side by side and therefore we needed a os
independent system. As we started Qt was not around as open source for
windows.

Now you could ask why we didn't choose something like LAMP. The answer
is quite simple, we didn't want to fiddle around with html and some
embedded stuff or even worse with cgi scripts. So the result is a kind
of a abstraction layer that handles the normal web stuff but can be
programmed like a gui.

As a result the application programmer doesn't have to bother if it is
a web application delivered through a webserver or if it is a gui
application delivered through X11 or other pixel painting engines.

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


Re: Windows and python execution

2005-12-27 Thread Peter Hansen
Peter Hansen wrote:
> BartlebyScrivener wrote:
What you need to do is include the following line in autoexec.bat:
set .py=c:\python24\python.exe
>>
>>Whatever works for you. I don't have that command in my autoexec.bat
>>file and my python scripts execute from any location because the
>>directory they are stored in is in my PATH variable.
...
> Merely adding the folder containing the EXE to PATH does *not* let you 
> avoid typing "python" before the script name, as your posts imply.

D'oh... okay, people (including me) are reading others' posts with 
preconceptions about what they are talking about in mind.

The PATHEXT thing is required to be able to type just "scriptname" 
_without_ the .py extension.  Alternatively, it appears there's yet 
another obscurely documented feature involving setting environment 
variables that resemble file extensions, as posted by others.  (Where do 
these things come from?  It's like Microsoft releases the OS, then 
periodically sends private emails to random people, pointing out obscure 
new features, so that they can tell others in some feeble effort to make 
using Windows look like a grassroots effort or something.  How are 
regular mortals supposed to find out about things like "set .py="?)

The ability to run the script with just "scriptname.py" comes from, I 
believe, having a file association set up with "ftype" and "assoc" or 
the equivalent registry entries.  For this to work from _any_ location 
one must have the folder containing the *script* in the PATH, as with 
any executable, while the path specified by FTYPE points to the Python 
executable.  (This ftype/assoc file association is set up by the 
standard installer, which is why it works for BartlebyScrivener).

-Peter

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


Re: Windows and python execution

2005-12-27 Thread Peter Hansen
BartlebyScrivener wrote:
>>>What you need to do is include the following line in autoexec.bat:
>>>set .py=c:\python24\python.exe
> 
> 
> Whatever works for you. I don't have that command in my autoexec.bat
> file and my python scripts execute from any location because the
> directory they are stored in is in my PATH variable.

But only because you type "python scriptname.py" instead of just 
"scriptname.py", right?  Or because something or someone (I don't 
believe the standard distribution does this) changed the PATHEXT 
environment variable to contain ".PY" somewhere.

Merely adding the folder containing the EXE to PATH does *not* let you 
avoid typing "python" before the script name, as your posts imply.

-Peter

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


Re: how to convert string like '\u5927' to unicode string u'\u5927'

2005-12-27 Thread Fredrik Lundh
Ganesan Rajagopal wrote:

>> unicodeStrFromNetwork = '\u5927'
>> unicodeStrNative = _unicodeRe(unisub, unicodeStrFromNetwork)
>
> How about unicodeStrNative = eval("u'%s'" % (unicodeStrFromNetwork,))

unicodeStrFromNetwork = "' + str(__import__('os').system('really bad idea')) + 
'"

 



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


  1   2   >