RE: seaching a list...

2006-08-11 Thread Gabriel Genellina

At Thursday 10/8/2006 21:54, bruce wrote:


the issue i'm having is that i'm going to have to compare multiple rows of
information to the information in the db. so essentially i'd have to do a
hit to the db, for each row of information i want to compare if i did it
your way... (which was what i had thought about)

the issue of doing the string/list compare/search is that i can get
everything from the db with one call... i can then iterate through memory
for each of my row information that i'm searching to see if it exists in the
db...

memory searches should be faster than the network overhead, and the
associated multiple db calls...


should... are you sure?
How many rows on the database? how many rows to compare? network overhead?
Do some timing/performance tests to evaluate that. Things aren't 
always as you expect.




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: semi-Newbie question

2006-08-11 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, len wrote:

> mycode = "TagToSQL['mySQLfieldname'] = Tagfile['Value']"
> exec mycode

Why do you use ``exec`` here?  Why not simply::

  TagToSQL['mySQLfieldname'] = Tagfile['Value']

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sys.platform documentation?

2006-08-11 Thread Michiel Sikma

Op 10-aug-2006, om 19:18 heeft Simon Forman het volgende geschreven:

> It might be a good idea to write a brief script to print out
> sys.platform, platform.platform(), platform.uname(), etc..  and  
> post it
> here for people to run and post their results.
>
> Peace,
> ~Simon
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

sys.platform is actually not needed anymore once you use platform, it  
seems.

So if you run this script:
--
import platform
platform.platform()
platform.uname()
--
You will get all the information that is necessary. And then you just  
need to provide it with a human-determined name of the operating  
system you're using.

My output:

  >>> import platform
  >>> platform.platform()
  'Darwin-8.6.0-Power_Macintosh-powerpc-32bit'
  >>> platform.uname()
  ('Darwin', 'imac-g5-van-michiel-sikma.local', '8.6.0', 'Darwin  
Kernel Version 8.6.0: Tue Mar  7 16:58:48 PST 2006;  
root:xnu-792.6.70.obj~1/RELEASE_PPC', 'Power Macintosh', 'powerpc')

And I'm on Mac OS X 10.4.6 on a G5 iMac.

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


kerberos under windows

2006-08-11 Thread Kamil Malinka
Hi

i'd like to know, is there any package like pykpass for windows? Or how 
to use this under windows. I need to authenticate users with kerberos 
under windows environment and have no idea how.
Thanks for help.

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


Python script setup

2006-08-11 Thread 2Good4You-Veki(Cro)
Hi all,

When I want setup my script:

I write:

from distutils.core import setup
setup(name="myscript",
 version='1.0',
 scripts=["myscripts.py"])

or some else example,error is


Traceback (most recent call last):
  File "", line 1, in -toplevel-
setup(name="myscript",
 version='1.0',
 scripts=["myscripts.py"])
  File "C:\Python24\distutils\core.py", line 101, in setup
_setup_distribution = dist = klass(attrs)
  File "C:\Python24\distutils\dist.py", line 130, in __init__
setattr(self, method_name, getattr(self.metadata, method_name))
AttributeError: DistributionMetadata instance has no attribute
'get___doc__'

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


RE: sys.platform documentation?

2006-08-11 Thread Tim Golden
[Michiel Sikma]
| So if you run this script:
| --
| import platform
| platform.platform()
| platform.uname()
| --
| You will get all the information that is necessary. And then 
| you just  
| need to provide it with a human-determined name of the operating  
| system you're using.

If you're interested:

>>> platform.platform()
'Windows-XP-5.1.2600-SP2'
>>> platform.uname()
('Windows', 'VOGBP350', 'XP', '5.1.2600', '', '')
>>>

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: "running" code on client side with cherrypy?

2006-08-11 Thread Bruno Desthuilliers
Mr BigSmoke wrote:
> Tnx Jay... as i supposed there's no easy solution... I just thought
> that, maybe, being on an intranet there was a possible solution...
> About pysvn a tortoise... i do use tortoiseSVN and t works really
> really fine.. we (developers) use it, but i'm writting server for
> "normal" users that can checkout our applications releases...

If the goal is to allow final users to download releases, then it's
simpler - you just have to serve them with archived (zipped, tarballs,
Python-Eggs, whatever) versions of the last release so they can download
it - the browser will then ask them where tehy want to save it.

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


Re: hide python code !

2006-08-11 Thread Bruno Desthuilliers
Bayazee wrote:
> hi
> can we hide a python code ?
> if i want to write a commercial software can i hide my source code from
> users access ?
> we can conver it to pyc but this file can decompiled ... so ...!!

It's just the same with java byte-code or machine code. FWIW, I had a
cracked (and localised) copy of Steinberg's Cubase midi sequencer v1.1
*before* v1.0 was publicly available in France... And believe me, they
had made their best to protect the software (dongle etc...).

The only secure way to protect "critical" code is to not distribute it -
make it run on your own server, and require the application to access
the server.


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


Re: hide python code !

2006-08-11 Thread Bruno Desthuilliers
Steven D'Aprano wrote:
(snip)
> If you really want something which compiles to machine code, then Python
> is not the language for you. Use another language. 
> 

But that won't protect your software from piracy anyway.

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


Component framework

2006-08-11 Thread Jan Svec
Hi all,
some time ago I've seen an interesting component framework for Python
but I don't remember the name. I remember only one example. There were
two components: Wheel and Car, Wheel were then inserted four times into
Car and so on. This framework has had lazy instantiation of child
components.

Does anybody know the name of this framework?

Thanks,
Honza

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


Reading unformatted big-endian files

2006-08-11 Thread Andrea Gavana
Hello NG,

that may sound a silly question, but I didn't find anything really
clear about the issue of reading unformatted big endian files with
Python. What I was doing till now, was using Fortran to read those
files and compile this Fortran extension using F2PY. Now that it seems
that no possible combinations of Fortran/C compilers actually *work*
with Python 2.4 on Windows XP, I was trying to translate the Fortran
subroutine to Python. Basically, what I do (in Fortran, I hope to
explain the code clearly) is:

! Declare an integer
integer number

! Declare a 4-chars character
character*4 keytype

! Declare a 8-chars character
character*8 keyword

! feof is not very important here
logical feof
feof = .false.

! Open the file as unformatted big-endian
open(unit = , file = filename, form = 'UNFORMATTED', convert = 'BIG_ENDIAN')

! loop until you find a particular keyword
! here "end=10" means that if the routine finds the EOF, it should go to
! the label "10 continue". "err=8" means that, if an error occours in
reading the file,
! it should go to the label "8 continue" and continue reading the file

do while(.not.feof)

! Read the 3 variables keyword, number and keytype
read(1, end=10, err=8) keyword, number, keytype

! If the keyword is 'DIMENS', break the loop and go to the end
if (keyword == 'DIMENS') then
read(1, end=10, err=8) dimens
goto 10
endif
8  continue
enddo

10continue

! Close the file
close(1)


Well, does anyone have some suggestion about which kind of
material/tutorial on similar things I should read? How can I deal in
Python with variables that must be 8-chars or 4-chars in order to read
correctly the file? Am I missing something else?

Thank you very much for every suggestion.

Andrea.

-- 
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.virgilio.it/infinity77/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hide python code !

2006-08-11 Thread Rob Wolfe

John Machin wrote:

> If you want to distribute obfuscated code, consider writing it in perl
> :-)

LOL

That's really strong protection. Machine code is too easy
to reverse engineer. :)

Regards,
Rob

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


Read a file with open command

2006-08-11 Thread jean-jeanot
I can access to a file with the command:
file_obj = open ( " D:\My documents\Textfile.txt",'r')

When I now try to read a file with the following command:

file_obj = open ("D:\My documents\File.ods",'r') it doesn't function.
The extension ods is coming from OpenOffice.org Calc.

Why ?

jean-jeanot

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


Re: using python to edit a word file?

2006-08-11 Thread Anthra Norell
John,

  I have a notion about translating stuff in a mess and could help you with 
the translation. But it may be that the conversion
from DOC to formatted test is a bigger problem. Loading the files into Word and 
saving them in a different format may not be a
practical option if you have many file to do. Googling for batch converters DOC 
to RTF I couldn't find anything.
  If you can solve the conversion problem, pass me a sample file. I'll 
solve the translation problem for you.

Frederic


- Original Message -
From: "John Salerno" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To: 
Sent: Thursday, August 10, 2006 9:08 PM
Subject: Re: using python to edit a word file?


> John Salerno wrote:
>
> > But if I save the file to text, won't it lose its formatting?
>
> It looks like I can save it as an XML file and it will retain all the
> formatting. Now I just need to decipher where the dates are in all that
> mess and replace them, just using a normal text file! :)
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Python script setup

2006-08-11 Thread John Machin

2Good4You-Veki(Cro) wrote:
> Hi all,
>
> When I want setup my script:
>
> I write:
>
> from distutils.core import setup
> setup(name="myscript",
>  version='1.0',
>  scripts=["myscripts.py"])
>
> or some else example,error is
>
>
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-

Do you get the same result if you put those Python statements in a file
(typically named setup.py) and run it in the Windows "Command Prompt"
window as shown in the manual:

http://docs.python.org/inst/standard-install.html

instead of using pyshell? Where/how are you supplying the "install"
argument when using pyshell?

> setup(name="myscript",
>  version='1.0',
>  scripts=["myscripts.py"])
>   File "C:\Python24\distutils\core.py", line 101, in setup

My distutils is where I'd expect it to be (C:\Python24\Lib\distutils)
because that's where the standard Python installation puts it relative
to my choice of the Python installation directory (C:\Python24).
How did yours end up like that? Did you download distutils and install
it as a separate package? If so, how did you install it?
What version of Python are you using?

> _setup_distribution = dist = klass(attrs)
>   File "C:\Python24\distutils\dist.py", line 130, in __init__
> setattr(self, method_name, getattr(self.metadata, method_name))
> AttributeError: DistributionMetadata instance has no attribute
> 'get___doc__'

HTH,
John

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


Re: Read a file with open command

2006-08-11 Thread Jan Svec
Hi,
simply use file_obj = open ("D:\My documents\File.ods",'rb') for
opening file in binary access mode, which is required for binary files
on MS Windows.
Honza

jean-jeanot wrote:
> I can access to a file with the command:
> file_obj = open ( " D:\My documents\Textfile.txt",'r')
>
> When I now try to read a file with the following command:
>
> file_obj = open ("D:\My documents\File.ods",'r') it doesn't function.
> The extension ods is coming from OpenOffice.org Calc.
> 
> Why ?
> 
> jean-jeanot

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


Python checking for None/Null values

2006-08-11 Thread Fuzzydave
Okay, I have been handed a python project and working through it I have

had to add a report. I am returning 10 variables the results of an SQL
Query
and as usual the number of results vary from 1 result to 10 results so
I
implemented a check to see if the array item was empty or not. The code

is below based upon the code already in the python project i was
handed.

history8=historyRep[8]
if history8!=None:
history8=cmi.format_history(historyRep[8])
else:
history8=''

and

if historyRep[8]!=None:
history8=cmi.format_history(historyRep[8])
else:
history8=''

but regardless i am getting the error below and i can't seen to resolve
this, what am i
doing wrong?

Traceback (most recent call last): File
"/home/phillipsd/work/medusa-new/htdocs/pricingrep.cgi", line 326, in ?
if historyRep[8]==None: IndexError: list index out of range


David P

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


Re: Reading unformatted big-endian files

2006-08-11 Thread John Machin
Andrea Gavana wrote:

> "err=8" means that, if an error occours in
> reading the file,
> it should go to the label "8 continue" and continue reading the file

Silently ignoring errors when reading a file doesn't sound like a good
idea to me at all, especially if different records have different
formats.

>
> Well, does anyone have some suggestion about which kind of
> material/tutorial on similar things I should read? How can I deal in
> Python with variables that must be 8-chars or 4-chars in order to read
> correctly the file?

(a) read the docs on the struct module
(b) eyeball this rough untested translation:
8<---
def filereader(filename):
import struct
f = open(fname, 'rb') # 'rb' is read binary, very similar to C
stdio
fmt = '>8si4s'
# Assuming unformatted means binary,
# and integer means integer*4, which is signed.
# Also assuming that the 3-variable records are fixed-length.
fmtsz = struct.calcsize(fmt)
while True:
buff = f.read(fmtsz)
if not buff: # EOF
break
keyword, number, keytype = struct.unpack(fmt)
keyword = keyword.rstrip() # remove trailing spaces
keytype = keytype.rstrip()
if keyword == 'DIMENS':
# 'dimens' is neither declared nor initialised in the
FORTRAN
# so I'm just guessing here ...
buff2 = f.read(4)
dimens = struct.unpack('>i', buff2)
break
print keyword, number, keytype # or whatever
# reached end of file (dimens *NOT* defined),
# or gave up (dimens should have a value)
f.close() # not absolutely necessary especially when only reading

if __name__ == "__main__":
import sys
filereader(sys.argv[1])
8<---

If this doesn't work, and it's not obvious how to fix it, it might be a
good idea when you ask again if you were to supply a
FORTRAN-independent layout of the file, and/or a dump of a short test
file that includes the DIMENS/dimens caper -- you can get such a dump
readily with the *x od command or failing that, use Python:

#>>>repr(open('thetestfile', 'rb').read(100)) # yes, I said *short*

HTH,
John

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


Re: Python checking for None/Null values

2006-08-11 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Fuzzydave
wrote:

> but regardless i am getting the error below and i can't seen to resolve
> this, what am i
> doing wrong?
> 
> Traceback (most recent call last): File
> "/home/phillipsd/work/medusa-new/htdocs/pricingrep.cgi", line 326, in ?
> if historyRep[8]==None: IndexError: list index out of range

`historyRep` seems to be shorter than you think it is.  Try printing it
too see what it actually contains.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Reading unformatted big-endian files

2006-08-11 Thread Andrea Gavana
Hello John,

>Silently ignoring errors when reading a file doesn't sound like a good
>idea to me at all, especially if different records have different
>formats.

Yeah, you're right, but the file itself is quite big and I am
interested only in a small part of it. Moreover, the sequence
keyword-number-keytype is unlikely to fail to be read unless the
simulator that outputs the file does something very strange.

> (a) read the docs on the struct module

Yes, I have done it, and I have written something similar to what you
propose (well, actually your solution is more elegant than mine :-D )

>if keyword == 'DIMENS':
># 'dimens' is neither declared nor initialised in the FORTRAN
># so I'm just guessing here ...

Sorry, I forgot to include it, 'dimens' is an integer(4)

Thank you very much for your explanation, now it is very clear what I
should do. I hope performances will not change so much: fortran is
very fast in reading files (but I use it only in this case, I love to
use Python)... well, let's see :-D

Andrea.

-- 
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.virgilio.it/infinity77/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read a file with open command

2006-08-11 Thread John Machin
jean-jeanot wrote:
> I can access to a file with the command:
> file_obj = open ( " D:\My documents\Textfile.txt",'r')

With a space before the drive letter? I don't think so.
When asking questions, *don't* type what you thought you used,
copy/paste what you actually used.

>
> When I now try to read a file with the following command:
>
> file_obj = open ("D:\My documents\File.ods",'r') it doesn't function.
> The extension ods is coming from OpenOffice.org Calc.
>
> Why ?

You haven't told us what "it doesn't function" means, so we'll have to
play guessing games ...could be for at least two possible reasons:
(1) .ods files are binary and you didn't specify 'rb'
(2) you really typed "d:\my documents\file.ods" and the \f got
interpreted as a form-feed character. You should *never* type literal
Windows filenames like that. Instead, you have three choices:
(a) "d:\\my documents\\file.ods" # not recommended
(b) r"d:\my documents\file.ods"
(c) "d:/my documents/file.ods"

I'd suggest that you fix *both* of the above problems and try again.

HTH,
John

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


Re: Python checking for None/Null values

2006-08-11 Thread Fuzzydave
> `historyRep` seems to be shorter than you think it is.  Try printing it
> too see what it actually contains.
>
> Ciao,
>   Marc 'BlackJack' Rintsch

HistoryRep is an array value so historyRep[0] to [7] all have values
in them but historyRep[8] and [9] do not as the query does not always
return a full 10 values. I am trying to check all of the historyRep
items
to check if they are empty/null/None (whatever the term is in python)
and make it return an empty value or a none to the screen. I did print
historyRep[8] out and it falls over, I am assuming if its an array and
if the SQL query only returns 8 records instead of 10 then the last
two array values i am checking for litterly don't exist instead of
being 
null but i can't find a if exists style function either?

David P

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


Re: easy string formating question

2006-08-11 Thread Slawomir Nowaczyk
On Thu, 10 Aug 2006 17:28:59 -0700
Simon Forman <[EMAIL PROTECTED]> wrote:

#> There is a better way to check for exhausted StringIO (Note that
#> "input" is a python built-in and should not be used for a variable
#> name):

Right, thanks for pointing it out.

#> import StringIO
#> s = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
#> size = 10  # 100
#> S = StringIO.StringIO(s)
#> 
#> data = S.read(size)
#> while data:
#> print data + "?\n",
#> data = S.read(size)

It may be only my personal opinion, but duplicating data = S.read(size)
line doesn't strike me as particularly better.

#> However, it's considered more "pythonic" to do it like so (also uses a
#> StringIO as an output "file" to show how print can print to a file-like
#> object):
#> 
#> import StringIO
#> 
#> s = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
#> size = 10  # 100
#> 
#> S = StringIO.StringIO(s)
#> out = StringIO.StringIO()# stand-in for a real file.
#> 
#> while True:
#> data = S.read(size)
#> if not data:
#> break
#> print >> out, data + "?\n",
#>
#> print out.getvalue()

This looks slightly nicer, but still, I wish there was some kind of
StringIO.isEOF() to put in while condition.

Don't take me wrong, I love "while True" stuff, but sometimes having
an actual test there can be nice :)

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

Beware of bugs in the above code; I have only proved it correct,
not tried it.

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


Re: hide python code !

2006-08-11 Thread Slawomir Nowaczyk
On Thu, 10 Aug 2006 17:35:27 -0700
enigmadude <[EMAIL PROTECTED]> wrote:

#> 2. I've never done this, but you might be able to encrypt or otherwise
#> turn you modules into binary form, and then use a clever import
#> hook.

Please observe that whatever the "clever import hook" is, it actually
needs to know the way to *decrypt* the module (secret key or
whatever). It means that if somebody decompiles the importing code, he
can just as well decompile the "hidden" one.

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

Children are natural mimics, who act like their parents despite
every effort to teach them good manners.

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


Re: converting a nested try/except statement into try/except/else

2006-08-11 Thread Slawomir Nowaczyk
On Thu, 10 Aug 2006 16:42:47 -0700
Simon Forman <[EMAIL PROTECTED]> wrote:

#> 6.) There's a single return statement.
#> 
#> I forget now where I picked this up, but it's served me well for
#> many years: Procedures, functions, methods, etc... should have one
#> exit point. Something about having fewer "code paths" to test or
#> something.

Number of return statements has absolutely *nothing* to do with number
of code paths to test.

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

Only drug dealers and software companies call their customers 'users.'

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


Re: Nested function scope problem

2006-08-11 Thread Slawomir Nowaczyk
On Wed, 09 Aug 2006 15:11:16 -0300
Gerhard Fiedler <[EMAIL PROTECTED]> wrote:

#> On 2006-08-09 07:54:21, Slawomir Nowaczyk wrote:
#> 
#> > Nope. Equivalence table can look like this:
#> > 
#> >Python C
#> > variable:a  variable:  a
#> > textual representation: "a" address operator: &a
#> > id of object:   id(a)   dereference operator: *a
#> > 
#> > Also, notice, that "id(a)" does not really "identify" a variable. It
#> > only identifies *object* which is bound to this variable. Both in
#> > Python and in C.
#> 
#> Rests one question: what is the value of the variable? In Python, it would
#> be the result of "a". In C, it would be the result of ...? 

Hmmm, well, it should be value of a, but it clearly doesn't make much
sense. It seems like I got confused and was saying something else than
I was thinking.

So, indeed, you were right: this analogy is broken.

But let me try again, please (just one more time, if this doesn't work
either I am willing to admit I do not see a simple analogy between
Python and C variables :-)

   Python C
variable:   avariable:  a
value of variable:  eval("a")dereference operator: *a
textual representation: "a"  address operator: &a
id of object:   id(a)value of variable: a

Thus, equivalent operations would be:

   Python C
a = 1003 a = &three  // (1)
id(a)a
b = 1004 b = &four
a == b  # False  *a == *b// false
id(a) == id(b)  # False  a == b  // false
b = ab = a 
a == b  # True   *a == *b// true
id(a) == id(b)  # True   a == b  // true
a = 1001+1002a = MallocNewIntFromValue( one+two )
a == b  # True   *a == *b// true
id(a) == id(b)  # False / True (2)   a == b  // false / true
a = 1003+1004a = MallocNewIntFromValue( three+four )
a == b  # False  *a == *b// false
id(a) == id(b)  # False  a == b  // false


(1) one, two, three and four are constants, something like "const int
one = 1". That is because there is no "literal int object" in C
- the thing you would write as "1" is likely not to actually
exist at runtime. And you cannot take an address of it.

(2) is actually True in CPython implementation for small integers, but
that's a minor detail. MallocNewIntFromValue might cache objects
as well.

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

Housework can't kill you... but why take a chance?

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


Re: Python checking for None/Null values

2006-08-11 Thread Fuzzydave
> Check with "if history8 is not None". Won't help your problem, but it
> is a bit more pythonic code ;-)
>
> Sybren

Actually i tried that as well when i was fooling around, atm i am less
concenred
with pythonic code and making it work in the first place. The entire
program to
be fair is a bit messy but i do agree on the basis that the easier the
code is to 
read the easier it is to work with.

David P

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


Rendering Vector Graphics

2006-08-11 Thread Bytter
Hi ppl,

I've already posted this message through the mailing-list, but it seems
it never arrived here. Strange... Anyway:

I need to render high-quality vector graphics with Python. I was
thinking of something like 'cairo', though I need to run under win32
and can't find a pycairo package for it. Suggestions?

Thanks,

Hugo Ferreira

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


Re: Rendering Vector Graphics

2006-08-11 Thread h112211
> I need to render high-quality vector graphics with Python. I was
> thinking of something like 'cairo', though I need to run under win32
> and can't find a pycairo package for it. Suggestions?

I've had good experiences doing simple 3d vector stuff with Pygame.
It's wraps SDL so it has pretty nice capabilities.

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


Re: Reading unformatted big-endian files

2006-08-11 Thread John Machin
On 11/08/2006 8:35 PM, Andrea Gavana wrote:

> I hope performances will not change so much: fortran is
> very fast in reading files (but I use it only in this case, I love to
> use Python)... well, let's see :-D

 Well FORTRAN would have to have *something* going for it :-)
I vaguely recall in a previous incarnation tarting up a vanilla ratfor 
"compiler" with switch statements and macros and all sorts of goodies so 
that life was less unbearable :-) [this was *before* f77]


Suggestions:
(1) Upgrade to 2.5 as soon as it goes final -- struct's performance has 
been improved.
(2) Consider the possibility of not unpacking all three variables if you 
don't need to -- for example if you are ignoring everything until you 
hit a record that starts with 'DIMENS  ', you don't need to unpack 
anything, just do:

if buff[:8] == 'DIMENS  ':

How big are your files, anyway?

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python checking for None/Null values

2006-08-11 Thread bearophileHUGS
Fuzzydave:

> I am trying to check all of the historyRep items
> to check if they are empty/null/None (whatever the term is in python)

An item can't be empty in Python,and null doesn't exist, it can be the
object None. But probly that's not your case.


> I did print
> historyRep[8] out and it falls over, I am assuming if its an array and
> if the SQL query only returns 8 records instead of 10 then the last
> two array values i am checking for litterly don't exist instead of
> being null but i can't find a if exists style function either?

A way to solve your problem is to see how many elements the list
contains with
len(sequence)
then act accordingly with the elements that exist.
Even better is to work on the elements that exist, with something like:
for element in sequence:
do_stuff

Note: sometimes having a clean and readable program is better than
having a running program that you can't read, because you can fix the
the first one, and it can teach you something.

Bye,
bearophile

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


Re: Python checking for None/Null values

2006-08-11 Thread Fuzzydave
> Note: sometimes having a clean and readable program is better than
> having a running program that you can't read, because you can fix the
> the first one, and it can teach you something.
>
> Bye,
> bearophile

Thanks for your help and suggestions i'll give them a shot.

Unfortunatly when working with 6 years of other peoples legacy code
(esspecially *this* code) it sometimes looks like it was specifiyed in
the
project spec *not* to be readable :)

But I will endevour to change that while working with it myself ;)

David P

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


Re: Python checking for None/Null values

2006-08-11 Thread John Machin
Fuzzydave wrote:
>
> HistoryRep is an array value so historyRep[0] to [7] all have values
> in them but historyRep[8] and [9] do not as the query does not always
> return a full 10 values. I am trying to check all of the historyRep
> items
> to check if they are empty/null/None (whatever the term is in python)
> and make it return an empty value or a none to the screen. I did print
> historyRep[8] out and it falls over, I am assuming if its an array and
> if the SQL query only returns 8 records instead of 10 then the last
> two array values i am checking for litterly don't exist instead of
> being
> null but i can't find a if exists style function either?

Just paste this in immediately after getting the result back from the
query; it's not necessarily the fastest way but it's effin' obvious
what it's doing :-)

while len(historyRep) < 10:
historyRep.append(None)

Cheers,
John

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


Re: Python checking for None/Null values

2006-08-11 Thread Peter Otten
Fuzzydave wrote:

> Okay, I have been handed a python project and working through it I have
> had to add a report. I am returning 10 variables the results of an SQL
> Query and as usual the number of results vary from 1 result to 10 results
> so I implemented a check to see if the array item was empty or not. The
> code is below based upon the code already in the python project i was
> handed.

In Python list items do not magically spring into existence if you ask for
them. Therefore items[index] raises an IndexError if index is >=
len(items). A possible resolution is to check the length of historyRep
first:

if len(historyRep) > 8 and historyRep[8] is not None:
history8 = cmi.format_history(historyRep[8])
else:
history8 = ""

Note that names like history8 are a strong indication that you should use a
list rather than individual variables, e. g:

history = []
for item in historyRep:
if item is None:
s = ""
else:
s = cmi.format_history(item)
history.append(s)

or maybe even

history = [cmi.format_history(item) for item in historyRep]

if historyRep doesn't contain any None values.

Peter

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


Re: Rendering Vector Graphics

2006-08-11 Thread Bytter
Hi!

[EMAIL PROTECTED] wrote:

> > I need to render high-quality vector graphics with Python. I was
> > thinking of something like 'cairo', though I need to run under win32
> > and can't find a pycairo package for it. Suggestions?
>
> I've had good experiences doing simple 3d vector stuff with Pygame.
> It's wraps SDL so it has pretty nice capabilities.

What about 2D? I won't be doing any 3d stuff, though I need
high-quality 2D, and complex stuff like defining clipping regions with
bezier curves and filling with gradients.

Thanks!

Hugo Ferreira

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


Re: Component framework

2006-08-11 Thread Michael
Jan Svec wrote:

> Hi all,
> some time ago I've seen an interesting component framework for Python
> but I don't remember the name. I remember only one example. There were
> two components: Wheel and Car, Wheel were then inserted four times into
> Car and so on. This framework has had lazy instantiation of child
> components.
> 
> Does anybody know the name of this framework?

PEAK - http://peak.telecommunity.com/Articles/WhatisPEAK.html

"""PEAK is the "Python Enterprise Application Kit". If you develop
   "enterprise" applications with Python, or indeed almost any sort of
   application with Python, PEAK may help you do it faster, easier, on a
   larger scale, and with fewer defects than ever before. The key is
   component-based development, on a reliable infrastructure."""

FWIW, I don't use it, but I'm aware of it. I use a component framework I
develop for work & fun called Kamaelia - but PEAK is what you're thinking
of.

BTW, since it might be helpful, from your request I punched the following
search terms into google - which links to the tutorial mentioning cars and
wheels:
   * Search terms: wheel car component lazy python

:-)

Best Regards,


Michael.
--
Michael Sparks, Kamaelia Project Lead
http://kamaelia.sourceforge.net/Home
http://yeoldeclue.com/blog

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


Make $1000's Monthly!

2006-08-11 Thread dataentry . nilam . 1
Make $1000's Monthly!
Over 600 work at home firms are in need of survey takers, product
assemblers, home mailers, mystery
shopping
Data entry and more!  Report contains complete contact details for over
650 companies now hiring!
For this complete report of over 600 firms please visit
http://www.typeinternational.com/idevaffiliate/idevaffiliate.php?id=6589_52_3_87

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


Re: Rendering Vector Graphics

2006-08-11 Thread jay graves
Bytter wrote:
> Hi ppl,
> I've already posted this message through the mailing-list, but it seems
> it never arrived here. Strange... Anyway:
> I need to render high-quality vector graphics with Python. I was
> thinking of something like 'cairo', though I need to run under win32
> and can't find a pycairo package for it. Suggestions?

AGG (Anti-Grain Geometry) is one such engine that a couple of people
have interfaced to Python.
http://www.antigrain.com/

...
jay graves

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


Re: Rendering Vector Graphics

2006-08-11 Thread Yannick

Bytter wrote:
> Hi ppl,
>
> I've already posted this message through the mailing-list, but it seems
> it never arrived here. Strange... Anyway:
>
> I need to render high-quality vector graphics with Python. I was
> thinking of something like 'cairo', though I need to run under win32
> and can't find a pycairo package for it. Suggestions?
>
> Thanks,
>
> Hugo Ferreira

Hi,

You can use cairo through the pyGTK bindings. Works pretty well for me.

Cheers,
Yannick

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


Re: timeout calling local sendmail

2006-08-11 Thread [EMAIL PROTECTED]
That seems applicable to writing an SMTP server/daemon, but is it
necessary for a script client calling a local SendMail daemon?

Tim Williams wrote:
>
>
> RFC 1123
>
> http://www.freesoft.org/CIE/RFC/1123/109.htm
>
> I find that a timeout of 120 seconds is the bare minimum.   If the
> timeout  is too short you get a condition where the email is received
> succesfully but appears to the sending server to have failed and a
> retry may occur - so the recipient gets multiple copies.
> 
> HTH :)

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


Reading unformatted big-endian files

2006-08-11 Thread Andrea Gavana
Hello John,

> (1) Upgrade to 2.5 as soon as it goes final -- struct's performance has
> been improved.

I would love to, but I have some dependencies (like wxPython, Numeric,
py2exe and so on) for which a 2.5 stable release either doesn't exist
or is not fully tested or will break my app in some way. I believe
Numeric doesn't exist anymore (!) and I am somewhat afraid to use
numpy. It is a little bit more "hostile" :-D

> How big are your files, anyway?

Well, they ranges from 6-7 MB (the smallest) to 600-700 MB (the
biggest)... I will try the new script and see how it performs.

Thank you very much!

Andrea.

-- 
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.virgilio.it/infinity77/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generator-based microthreads and games

2006-08-11 Thread Michael
[EMAIL PROTECTED] wrote:

> I've seen various generator-based microthread implementations online,
> but I've been wondering: has anyone used microthreads in this manner in
> a game environment?  Note, I am emphatically *not* referring to
> Stackless, which I know has been used in a production game environment;
> this post is referring strictly to the standard Python interpreter, (v.
> 2.4 or 2.5 as you wish).
> 
> I intend to try a little cooperative microthreading implementation in
> my game server to avoid threading issues and possibly simplify the
> programming model.  This seems particularly attractive given the
> enhancements Python 2.5 brings to generators.
> 
> If anyone else has tried this, what I would like to know is this:

Several. I'll largely talk about our experience with Kamaelia below, but
there's also LGT which is also pretty interesting.

LGT: http://www.pygame.org/projects/9/20/
Kamaelia:

The reason I'll only talk about Kamaelia is because I'm the lead developer
on that project, and because I think it's a fun way to write this sort of
thing :-) 

Naturally I'm biassed, bear that in mind :-)

> * How many microthreads were you able to run concurrently with decent
> performance?

Numbered in the thousands. It's been a while since we've done any benchmarks
however. (Most of our use of generators has revolved around network
systems, but we use Pygame fairly heavily)

> * How much computation is feasible to carry out in a microthread?
> (Certainly, this goes hand in hand with the previous question, of
> course.)

As much as you like, however the more you do, the less microthreads you can
run (as you say, this goes hand in hand).

For short examples of what we're using generators for, take a peek here:
   * http://kamaelia.sourceforge.net/Cookbook.html

> * What sort of scheduler did you use?

We use a simple round robin scheduler.

> * Was it worth it?  By "worth it," I mean in terms of performance and
> ease of implementation.

Absolutely. There's a knock on of python style generators that people don't
tend to realise: it forces a your generators to be simple and focussed.

Given we augment generators with inboxes & outboxes for communications we
find we get higher levels of reuse of many components than we would
normally expect. We embed the generator in a class, giving far more
flexible communications that python 2.5's newly added facilities (this
approach works happily with python 2.2 onwards, meaning we've versions of
Kamaelia that even run on nokia phones.)

The only game we've written in Kamaelia at present is a simple bouncing cats
game (aimed at 2-4 year olds :-), which adds bouncing cats, and removes
them to a noise. However the only slow down I've really seen with that is
more due to the speed at which pygame & SDL can update the display AFAICT.

> I'll no doubt have further questions later after I actually begin
> implementing this stuff, but I suppose that will do for now.

Even if you're not interested in Kamaelia (then again you might - we find it
incredibly useful), you may find our tutorial useful - it shows you how to
go about building a simple scheduler and simple systems of communicating
generators in easy simple steps. (Tested on over a dozen novice python
programmers now).

   * http://kamaelia.sourceforge.net/MiniAxon/

Systems we're using this for:
   * Collaborative whiteboarding (every client is also a server) including
 audio
   * Transcoding PVR for making a record of transmission of all BBC TV
 channels, including collection of EPG data.
   * Under development - video annotation/editing. (for allowing
 collaborative discussion of how to post process video)

I suppose knocking up a simple game might be a nice thing to do as well :-)

For what it's worth, a focus in Kamaelia is on making it harder to do dumb
things when doing things in parallel - as you are doing when using threads
or generators. (That's the reason for the inbox/outbox metaphor - take it
out an inbox, it's yours to do what you want, put it in an outbox, you're
not allowed to do anything with it any more).

As a result generator based components and thread based components can be
mixed quite happily in Kamaelia, since you have explicit data handoff. This
might not seem immediately important to you, but as a system grows, you
need a way of handing blocking calls (since otherwise your generators and
scheduler stall), and putting those in a thread is a common idea. Doing
this safely is normally somewhat more complex than: (including imports)

import Axon
from Kamaelia.Chassis.Pipeline import pipeline
from Kamaelia.Util.Console import ConsoleEchoer

class ConsoleReader(Axon.ThreadedComponent.threadedcomponent):
   def main(self):
   while 1:
   data = raw_input(">>> ")  # block waiting for user
   self.send(data, "outbox") # send on to next thing

pipeline(
   ConsoleReader(), # Threaded Component
   ConsoleEchoer(), # Generator Component
).run()

Just as an indication of

Adding private tags to a tiff file.

2006-08-11 Thread O Evans
Hi there,

I'm manipualating tiff images captured by a program that insists on
using annoying private tags. I want to be able to import an image that
I have created into the program but I cannot get PIL to save the
private tag. Here is a simplified version of the code I am using:

import Image
original = Image.open(r"test.tif")
original.tag[34118] = "life"
print "Before saving" , original.tag[34118]
original.save("test2.tif")
altered = Image.open(r"test2.tif")
if altered.tag.tagdata.has_key(34118):
print "It worked!"

Is there a way of getting this to work? I have tried looking at
TiffTags and TiffImageFile, but I cannot understand why the tags are
not preserved. Or should I be looking at a different library?

Many thanks.

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


schedule at specific hours

2006-08-11 Thread Yves Glodt
Hi there,

I have a daemon running 24/7, and I want that it executes a certain function 
several times a day, as specified in an configfile (e.g. 
actiontimes=10:00,12:00,19:00)

Do I have to fiddle with sched.scheduler and calc. time differences to 
schedule my events, or is there another (nicer...) way?


Regards,
Yves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hide python code !

2006-08-11 Thread Paul Boddie
Cameron Laird wrote:
> Steven D'Aprano wrote:
> >Hiding source code is incompatible with Open Source software. You can hide
> >code, or be Open Source, but not both.

[...]

> I also disagree with your characterization of Open Source.

I don't know which part of the open source movement would tolerate the
hiding of source code whilst simultaneously calling the resulting
software "open source", but I'd imagine they'd have a hard time
justifying their "open source" label. Of course, it is possible to be
the "First Iranian Open Source Community" in terms of consuming open
source software rather than producing it, so perhaps that's what the
questioner intended to communicate in their signature.

[...]

> Myself, I just marvel at the different worlds in which we live.  *My*
> experience has to do with how tough it is to deploy and maintain
> correct, working stuff, even with teams of seasoned pros.  The thought
> that users will routinely reverse-engineer our applications, and ...
> well, I marvel.

I've previously mentioned a very interesting paper which not only
described the reverse engineering of the Skype protocol and software
but also described how to make interoperating Skype clients. Given that
the well-financed developers spent a lot of time introducing various
protection measures (encryption, verification, etc.) and yet someone
can write the aforementioned stuff up in a paper, I'd recommend an
upgrade to any business plan which relies on obfuscation to prevent
"unauthorised" use or modification. Indeed, I'd recommend that any such
entrepreneur think twice about starting a traditional proprietary
software business in this day and age.

Paul

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


Re: hide python code !

2006-08-11 Thread Fuzzyman

Bayazee wrote:
> hi
> can we hide a python code ?
> if i want to write a commercial software can i hide my source code from
> users access ?
> we can conver it to pyc but this file can decompiled ... so ...!!
> do you have any idea about this ...?
>
> ---
> First Iranian Open Source Community : www.python.ir


You can distribute the compiled byte-code files (*.pyc) which are
harder to turn back into source code.

There was a product called decompyle which could do it, but although
there is a version floating around which works for Python 2.4 I've
never heard of anyone getting it to work.

Import hooks and encrypted source are a good option.

Py2exe embeds the byte-code file for your main script into the
executable which is also pretty good.

All of these make it hard enough to deter most people who will ever
want to abuse your source code. Until you have *lots* of users this is
probably enough.

I never understand the knee-jerk reaction on this mailing list to
answer people who ask this question by telling them they don't really
want to do it...

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: hide python code !

2006-08-11 Thread Fuzzyman

Paul Boddie wrote:
[snip..]
> I've previously mentioned a very interesting paper which not only
> described the reverse engineering of the Skype protocol and software
> but also described how to make interoperating Skype clients. Given that
> the well-financed developers spent a lot of time introducing various
> protection measures (encryption, verification, etc.) and yet someone
> can write the aforementioned stuff up in a paper, I'd recommend an
> upgrade to any business plan which relies on obfuscation to prevent
> "unauthorised" use or modification. Indeed, I'd recommend that any such
> entrepreneur think twice about starting a traditional proprietary
> software business in this day and age.
>

How many users did skype have before that happened...

Several orders of magnitude above what is required to earn a living
from selling a few programs I suspect.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml


> Paul

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


Re: hide python code !

2006-08-11 Thread Paul Boddie
Fuzzyman wrote:
> Bayazee wrote:
> > can we hide a python code ?
> > if i want to write a commercial software can i hide my source code from
> > users access ?
> > we can conver it to pyc but this file can decompiled ... so ...!!

[...]

> You can distribute the compiled byte-code files (*.pyc) which are
> harder to turn back into source code.

As the man said, and I've seen various proprietary software companies
do just that.

> There was a product called decompyle which could do it, but although
> there is a version floating around which works for Python 2.4 I've
> never heard of anyone getting it to work.

I've got decompyle to work in the recent past (about a year or so ago)
- the trick was to find the Debian package and to make some minor
adjustments to the code to work with whatever breakage the 2.3 -> 2.4
upgrade caused.

[...]

> I never understand the knee-jerk reaction on this mailing list to
> answer people who ask this question by telling them they don't really
> want to do it...

Well, given the pace of technological development and the disregard in
some environments for perpetual backward compatibility, how much of
your infrastructure would you implement in vendor-supplied binaries,
especially when the vendor is a one man plus dog operation? When the
binaries don't work on your newly-upgraded system and the vendor is on
holiday (possibly for good), it doesn't look like a knee-jerk reaction
any more.

Paul

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


Re: hide python code !

2006-08-11 Thread Tim Chase
>> can we hide a python code ?
>> if i want to write a commercial software can i hide my source code from
>> users access ?
>> we can conver it to pyc but this file can decompiled ... so ...!!
> 
> All of these make it hard enough to deter most people who will ever
> want to abuse your source code. Until you have *lots* of users this is
> probably enough.
> 
> I never understand the knee-jerk reaction on this mailing list to
> answer people who ask this question by telling them they don't really
> want to do it...

I think the reaction is based mostly in reality...an honest 
answer:  If you give people the program, then you also give them 
the ability to reverse engineer it.  It's as simple as that.

No matter how dongled, obfuscated, compiled, encrypted, etc.  At 
some point the code actually has to be executed/interpreted, and 
at that point, it can be intercepted.  Thus, "by telling them 
that they don't really want to do it", the list is conveying the 
  futility of attempting to strive for the goal.  Obfuscation may 
be a shallow speedbump, and for some folks, better than nothing. 
  However, it's better to have a good relationship with your 
customers and know that they will adhere to licensing conditions, 
rather than to try and strong-arm them into behaving a particular 
way.

My "%s%0.2f" % (currency_marker, 0.02) on the matter. :)

-tkc




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


Re: hide python code !

2006-08-11 Thread Fuzzyman

Paul Boddie wrote:
> Fuzzyman wrote:
> > Bayazee wrote:
> > > can we hide a python code ?
> > > if i want to write a commercial software can i hide my source code from
> > > users access ?
> > > we can conver it to pyc but this file can decompiled ... so ...!!
>
> [...]
>
> > You can distribute the compiled byte-code files (*.pyc) which are
> > harder to turn back into source code.
>
> As the man said, and I've seen various proprietary software companies
> do just that.
>
> > There was a product called decompyle which could do it, but although
> > there is a version floating around which works for Python 2.4 I've
> > never heard of anyone getting it to work.
>
> I've got decompyle to work in the recent past (about a year or so ago)
> - the trick was to find the Debian package and to make some minor
> adjustments to the code to work with whatever breakage the 2.3 -> 2.4
> upgrade caused.
>
> [...]
>
> > I never understand the knee-jerk reaction on this mailing list to
> > answer people who ask this question by telling them they don't really
> > want to do it...
>
> Well, given the pace of technological development and the disregard in
> some environments for perpetual backward compatibility, how much of
> your infrastructure would you implement in vendor-supplied binaries,
> especially when the vendor is a one man plus dog operation? When the
> binaries don't work on your newly-upgraded system and the vendor is on
> holiday (possibly for good), it doesn't look like a knee-jerk reaction
> any more.
>

If you distribute applications with py2exe then your application is no
longer dependent on the installed version of Python.

The question keeps getting asked because a lot of new programmers are
looking to create programs that they will sell. A lot of these will be
good programmers, and some of the software will be successful. Telling
them 'you can't do that with Python', does no good to Python itself.

In fact what you can do with Python is not a lot worse than most other
languages, and almost certainly *good enough* for this sort of thing.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> Paul

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


datetime to timestamp

2006-08-11 Thread Simen Haugen
Hi.

How can I convert a python datetime to a timestamp? It's easy to convert
a timestamp to datetime (datetime.datetime.fromtimestamp(), but the
other way around...?)

-Simen

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


Re: hide python code !

2006-08-11 Thread Fuzzyman

Tim Chase wrote:
> >> can we hide a python code ?
> >> if i want to write a commercial software can i hide my source code from
> >> users access ?
> >> we can conver it to pyc but this file can decompiled ... so ...!!
> >
> > All of these make it hard enough to deter most people who will ever
> > want to abuse your source code. Until you have *lots* of users this is
> > probably enough.
> >
> > I never understand the knee-jerk reaction on this mailing list to
> > answer people who ask this question by telling them they don't really
> > want to do it...
>
> I think the reaction is based mostly in reality...an honest
> answer:  If you give people the program, then you also give them
> the ability to reverse engineer it.  It's as simple as that.
> [snip..]

But until your number of users gets beyond quite a high level, it's
just extremely likely that any of your individual users will have that
sort of ability - or anyone else will have the motivation to do it.

What you can do with Python is almost certainly *good enough* for most
people who ask this question - and that fact never seems to be included
in the 'reality' propogated by the knee jerk reactionists... :-p


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: hide python code !

2006-08-11 Thread Paul Boddie
Fuzzyman wrote:
> Paul Boddie wrote:

[Skype paper]

> > I'd recommend an
> > upgrade to any business plan which relies on obfuscation to prevent
> > "unauthorised" use or modification. Indeed, I'd recommend that any such
> > entrepreneur think twice about starting a traditional proprietary
> > software business in this day and age.
>
> How many users did skype have before that happened...
>
> Several orders of magnitude above what is required to earn a living
> from selling a few programs I suspect.

The point was that dreaming up exotic "protection" schemes for closed
source software is quite possibly only the highest priority in either a
highly traditional shrinkwrapped proprietary software business (where
the evidence - my spam folder - suggests that the "protection" is only
a marginally effective deterrent) or in some kind of proprietary
software plus services business where you don't want people tampering
with your infrastructure (where the evidence suggests that anyone
determined enough will force you to continually focus on that
"protection" scheme over the long-term).

So, if the questioner just wants to sell a few programs, they might
want to either consider different business models than those
traditionally envisaged, or they might want to be aware that fancy
"protection" is most likely to be a long-term investment yielding
moderately disappointing results, and that their energy is best
directed elsewhere.

Paul

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


Re: Python checking for None/Null values

2006-08-11 Thread Fuzzydave
> [EMAIL PROTECTED] wrote:
> A way to solve your problem is to see how many elements the list
> contains with
> len(sequence)


cheers after your post went of to try it and it worked first time
thanks 
for being helpful and plesant :)

Fuzzy

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


Re: hide python code !

2006-08-11 Thread Fuzzyman

Tim Chase wrote:
[snip]
>   However, it's better to have a good relationship with your
> customers and know that they will adhere to licensing conditions,
> rather than to try and strong-arm them into behaving a particular
> way.
>

Don't forget that distributing your source code is more of a gift to
your competitors (and potential competitors) than it is to your
customers...

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> My "%s%0.2f" % (currency_marker, 0.02) on the matter. :)
> 
> -tkc

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


Unit Testing Python

2006-08-11 Thread davidodowd
I am looking for a GUI to put on top of my unit testing framework. I
have found http://homepage.hispeed.ch/py430/python/unittestgui.py
through google, I have been unable to get the copy results function to
run I have downloaded the editor scite that it calls and still nothing
has anyone been able to get this working. Or does anyone know of a GUI
with greater functionality. Thanks a million :)

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


Re: hide python code !

2006-08-11 Thread Paul Boddie
Fuzzyman wrote:
> Paul Boddie wrote:
> > Fuzzyman wrote:
> >
> > > I never understand the knee-jerk reaction on this mailing list to
> > > answer people who ask this question by telling them they don't really
> > > want to do it...

Note your choice of words: "don't really want to do it".

[...]

> If you distribute applications with py2exe then your application is no
> longer dependent on the installed version of Python.

But there are numerous other things that might stop whatever binary it
is from working over longer periods of time. Besides, py2exe
executables don't exactly exhibit various typical benefits of normal
Python programs such as being able to run on more than one platform,
unless you recommend that everyone runs those applications in some kind
of Windows virtualisation solution.

> The question keeps getting asked because a lot of new programmers are
> looking to create programs that they will sell. A lot of these will be
> good programmers, and some of the software will be successful. Telling
> them 'you can't do that with Python', does no good to Python itself.

But many people admit that solutions do exist, notably py2exe and other
tools which do very similar things but for more than one platform (and
have done so for at least a decade). Now you did say that people are
being made to feel that they "don't really want to do it", but that's a
very different thing from being told that they "can't do that with
Python".

Personally, I'd rather people chose not to do such things with Python,
for various reasons including the inability of the end-user to study or
fix bugs in the code or to take advantage of various well-known
benefits of the Python language, library and runtime. But I do admit
that they at least can achieve some level of obfuscation or
"protection" for such endeavours (and a suitably-phrased Web search
will provide established solutions for doing just that).

Paul

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


Re: datetime to timestamp

2006-08-11 Thread John Machin
On 11/08/2006 11:10 PM, Simen Haugen wrote:
> Hi.
> 
> How can I convert a python datetime to a timestamp? It's easy to convert
> a timestamp to datetime (datetime.datetime.fromtimestamp(), but the
> other way around...?)
> 
> -Simen
> 

Is the timetuple() method what you want?

#>>> import datetime
#>>> n = datetime.datetime.now()
#>>> n
datetime.datetime(2006, 8, 11, 23, 32, 43, 109000)
#>>> n.timetuple()
(2006, 8, 11, 23, 32, 43, 4, 223, -1)

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime to timestamp

2006-08-11 Thread John Machin
On 11/08/2006 11:35 PM, John Machin wrote:
> On 11/08/2006 11:10 PM, Simen Haugen wrote:
>> Hi.
>>
>> How can I convert a python datetime to a timestamp? It's easy to convert
>> a timestamp to datetime (datetime.datetime.fromtimestamp(), but the
>> other way around...?)
>>
>> -Simen
>>
> 
> Is the timetuple() method what you want?
> 
> #>>> import datetime
> #>>> n = datetime.datetime.now()
> #>>> n
> datetime.datetime(2006, 8, 11, 23, 32, 43, 109000)
> #>>> n.timetuple()
> (2006, 8, 11, 23, 32, 43, 4, 223, -1)


Aaaarrrggghhh no it's not what you want -- looks like you have to do the 
arithmetic yourself, starting with toordinal()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: excel in unix?

2006-08-11 Thread Harry George
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
> > hi
> > is it possible to create excel files using python in Unix env?
> > if so, what module should i use?
> > thanks
> 
> Depending on the complexity of your data you might find the csv module
> useful.  It allows you to write comma separated value (.csv) files that
> Excel reads just fine.
> 

We use the csv module a lot.  I've also investigated the old DIF and
SLK formats for slightly more functoinality.  But the coming
standards-based world, if you need more than csv, start writing to to
the OpenOffice.org formats, either with your own code or via PyUNO.
Then use OOo itself or a MS-sponsored ODF reader to translate to Excel
format.  This should be a maintainable approach over time (but a lot
more complex than just csv).

-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter module not found

2006-08-11 Thread Shuaib
Well, I finally solved my problem. I just had to reinstall python with
the USE flags of tcl and tk.

#USE="tcl tk" emerge python

And now I can use Tkinter

Thanks guys!

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


Re: Rendering Vector Graphics

2006-08-11 Thread K.S.Sreeram
jay graves wrote:
> Bytter wrote:
>> Hi ppl,
>> I've already posted this message through the mailing-list, but it seems
>> it never arrived here. Strange... Anyway:
>> I need to render high-quality vector graphics with Python. I was
>> thinking of something like 'cairo', though I need to run under win32
>> and can't find a pycairo package for it. Suggestions?
> 
> AGG (Anti-Grain Geometry) is one such engine that a couple of people
> have interfaced to Python.
> http://www.antigrain.com/

Here are a couple of AGG wrappers for Python:
1) Fredrik Lundh's aggdraw allows you to draw AGG graphics on top of PIL
images.
2) You can also check out my dvpaint module. http://tachyon.in/davinci/
(It is a part of a larger vector graphics project which i hope to work
on sometime in the future.)

[sreeram;]



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Nested function scope problem

2006-08-11 Thread Gerhard Fiedler
On 2006-08-11 07:48:33, Slawomir Nowaczyk wrote:

> But let me try again, please (just one more time, if this doesn't work
> either I am willing to admit I do not see a simple analogy between
> Python and C variables :-)
> 
>Python C
> variable:   avariable:  a
> value of variable:  eval("a")dereference operator: *a
> textual representation: "a"  address operator: &a
> id of object:   id(a)value of variable: a
> 
> Thus, equivalent operations would be:
> 
>Python C
> a = 1003 a = &three  // (1)
> id(a)a
> b = 1004 b = &four
> a == b  # False  *a == *b// false
> id(a) == id(b)  # False  a == b  // false
> b = ab = a 
> a == b  # True   *a == *b// true
> id(a) == id(b)  # True   a == b  // true
> a = 1001+1002a = MallocNewIntFromValue( one+two )
> a == b  # True   *a == *b// true

Probably not True; b refers to the 1003 object, a refers to the 2003 
object. But that's just a minor "bug" in your selection of values :)  Your 
intention was probably to make a = 1001+2 in the line above.

> id(a) == id(b)  # False / True (2)   a == b  // false / true
> a = 1003+1004a = MallocNewIntFromValue( three+four )
> a == b  # False  *a == *b// false
> id(a) == id(b)  # False  a == b  // false
> 
> (1) one, two, three and four are constants, something like "const int
> one = 1". That is because there is no "literal int object" in C
> - the thing you would write as "1" is likely not to actually
> exist at runtime. And you cannot take an address of it.
> 
> (2) is actually True in CPython implementation for small integers, but
> that's a minor detail. MallocNewIntFromValue might cache objects
> as well.

I don't have a problem with that analogy. I guess we also agree that it has 
its limits (as all analogies have). However, with this analogy, a and b 
/must/ be pointer variables in C; the analogy does not work if a and b are 
not pointers. 

Which brings me back to my earlier statement: if it is at all possible to 
create a useful analogy between Python variables and C variables, it is 
between Python variables and C /pointers/. There is still no useful analogy 
between Python variables and general C variables (i.e. non-pointer 
variables). Note that non-pointer variables can contain objects, not only 
simple types. But they still are not analog.

Gerhard

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


some n00b question

2006-08-11 Thread Omar
I'm learning how to program python.  a few questions

a) I'm mostly interested in creating exe's that have to do with music
-- things to help me keep track of chord progressions, transpositions,
etc.  can anyone point me in the direction of resources on this?

b) I'm also interested in created GUI's sooner rather than later.  Can
anyone point me to a fast track to doing GUI's on python?

thanks

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


Re: Native Win32 text entry dialog?

2006-08-11 Thread utabintarbo

Well, to answer my own question

http://www.averdevelopment.com/python/EasyDialogs.html

Thanks to all who responded! ;-P

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


Re: hide python code !

2006-08-11 Thread Helmut Jarausch
John Machin wrote:
> Bayazee wrote:
>> hi
>> can we hide a python code ?
>> if i want to write a commercial software can i hide my source code from
>  [1]
>> users access ?
>> we can conver it to pyc but this file can decompiled ... so ...!!
>> do you have any idea about this ...?
>>
>> ---
>> First Iranian Open Source Community : www.python.ir
> ^^[2]
> 
> 
> [1] and [2] don't seem to be compatible.

I suppose all of you who have commented about this, are sitting in the
 >>> free world <<< .
But there are countries (like .ir) where the government has totally different
ideas of 'freedom'. So taking the freedom to write something can be very
dangerous at times. Fortunately most of those guys which intercept every
email and check every web server are not so smart to reverse engineer
everything in a short time since they have to check thousands of pieces of
information each day. Let's make their work a bit harder!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using python to edit a word file?

2006-08-11 Thread John Salerno
Anthra Norell wrote:
> John,
> 
>   I have a notion about translating stuff in a mess and could help you 
> with the translation. But it may be that the conversion
> from DOC to formatted test is a bigger problem. Loading the files into Word 
> and saving them in a different format may not be a
> practical option if you have many file to do. Googling for batch converters 
> DOC to RTF I couldn't find anything.
>   If you can solve the conversion problem, pass me a sample file. I'll 
> solve the translation problem for you.
> 
> Frederic

What I ended up doing was just saving the Word file as an XML file, and 
then writing a little script to process the text file. Then when it 
opens back in Word, all the formatting remains. The script isn't ideal, 
but it did the bulk of changing the numbers, and then I did a few things 
by hand. I love having Python for these chores! :)



import re

xml_file = open('calendar.xml')
xml_data = xml_file.read()
xml_file.close()

pattern = re.compile(r'(\d+)')

def subtract(match_obj):
 date = int(match_obj.group(1)) - 1
 return '%s' % date

new_data = re.sub(pattern, subtract, xml_data)

new_file = open('calendar2007.xml', 'w')
new_file.write(new_data)
new_file.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: schedule at specific hours

2006-08-11 Thread utabintarbo

Take a look at http://sourceforge.net/projects/pycron/ . It may give
you some ideas.

Bob

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


Re: converting a nested try/except statement into try/except/else

2006-08-11 Thread John Salerno
Boris Borcic wrote:
> Boris Borcic wrote:
>> John Salerno wrote:
>>> In this case the method must return False, because it's a wxPython 
>>> method that needs a True or False value. If it doesn't, the program 
>>> will continue even after the error message.
>>
>> Just as it should do if the method returns True and no error message 
>> is produced if I understand you well... Are you sure ? I don't know 
>> wxPython, but this strikes me as surprisingly unpythonic behavior.
> 
> I just verified on the wxWindows demo I had somehow installed on my box, 
> that indeed returning None appears to produce the same behavior as 
> returning True, distinct from the behavior obtained by returning False. 
> Ugh...

But since None == False is false, isn't it right that returning None 
wouldn't necessarily behave like returning False?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: some n00b question

2006-08-11 Thread John Salerno
Omar wrote:

> b) I'm also interested in created GUI's sooner rather than later.  Can
> anyone point me to a fast track to doing GUI's on python?

I recommend reading wxPython in Action. It's a great starter and 
reference to the wxPython GUI toolkit. Tkinter is usually considered 
easier and simpler, but I find it lacking in functionality, and wxPython 
is actually fairly easy to learn.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hide python code !

2006-08-11 Thread Ben Sizer
Paul Boddie wrote:
> Fuzzyman wrote:
> > I never understand the knee-jerk reaction on this mailing list to
> > answer people who ask this question by telling them they don't really
> > want to do it...
>
> Well, given the pace of technological development and the disregard in
> some environments for perpetual backward compatibility, how much of
> your infrastructure would you implement in vendor-supplied binaries,
> especially when the vendor is a one man plus dog operation? When the
> binaries don't work on your newly-upgraded system and the vendor is on
> holiday (possibly for good), it doesn't look like a knee-jerk reaction
> any more.

It's worth remembering that there is a massive amount of software that
has nothing to do with 'infrastructure', that won't need to be
maintained, or upgraded. Examples include most retail software for the
home or small office, and most entertainment software. Developers of
such software often have understandable reasons for making it
inconvenient to examine the algorithms at a high level.

-- 
Ben Sizer

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


Re: converting a nested try/except statement into try/except/else

2006-08-11 Thread John Salerno
Simon Forman wrote:

> I'm sorry to hear that.  I thought it was cleaner and more
> understandable than that.  May I indulge in explaining it a bit?  I
> can, perhaps, make it clearer.

Thanks for the explanation. I find that with a little concentration, 
it's not that it's hard to follow the code, just that I feel like I will 
need to 're-concentrate' each time I come back to it, because of the 
different variables being used in different places.

But I like the idea of making the try/except do very little, if not just 
one thing, so I'm going to keep studying it! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime to timestamp

2006-08-11 Thread Sion Arrowsmith
John Machin  <[EMAIL PROTECTED]> wrote:
>On 11/08/2006 11:35 PM, John Machin wrote:
>> On 11/08/2006 11:10 PM, Simen Haugen wrote:
>>> How can I convert a python datetime to a timestamp? It's easy to convert
>>> a timestamp to datetime (datetime.datetime.fromtimestamp(), but the
>>> other way around...?)
>> Is the timetuple() method what you want?
> [ ... ]
>Aaaarrrggghhh no it's not what you want -- [ ... ]

It is if you only want it to the second. It just needs a time.mktime():

>>> n = time.time()
>>> n
1155307613.4550381
>>> d = datetime.datetime.fromtimestamp(n)
>>> time.mktime(d.timetuple())
1155307613.0

(timetuple() is responsible for the loss of the fractional part.)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: datetime to timestamp

2006-08-11 Thread Tim Peters
[Simen Haugen]
>>> How can I convert a python datetime to a timestamp? It's easy to convert
>>> a timestamp to datetime (datetime.datetime.fromtimestamp(), but the
>>> other way around...?)

[John Machin]
>> Is the timetuple() method what you want?
>>
>> #>>> import datetime
>> #>>> n = datetime.datetime.now()
>> #>>> n
>> datetime.datetime(2006, 8, 11, 23, 32, 43, 109000)
>> #>>> n.timetuple()
>> (2006, 8, 11, 23, 32, 43, 4, 223, -1)

[also John]
> Aaaarrrggghhh no it's not what you want

Yes, it is ;-)

> -- looks like you have to do the arithmetic yourself, starting with 
> toordinal()

It's just one step from the time tuple:

import time
time.mktime(some_datetime_object.timetuple())

The datetime module intended to be an island of relative sanity.
Because the range of dates "timestamps" can represent varies across
platforms (and even "the epoch" varies), datetime doesn't even try to
produce timestamps directly -- datetime is more of an alternative to
"seconds from the epoch" schemes.  Because datetime objects have
greater range and precision than timestamps, conversion is
problem-free in only one direction.  It's not a coincidence that
that's the only direction datetime supplies ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Boost Install

2006-08-11 Thread Hoop
Hi All,
I am wondering if any have done an install of Boost for Python
embedding?
I have downoaded boost_1_33_1.exe, ran that and now have a boost_1_33_1
directory with plenty of items ine it.
I have attempted to follow some online install directions which do not
seem to work. I am using VS2005.
I have tried, bjam "--with-python-version[=2.4] and just get a
statement saying that bjam is not recognized. Really is no batch file
or executable with that name in the boost directory.
Not sure what to do to get the Boost.Python installed.
Thanks for any help.
Jeff

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


Re: hide python code !

2006-08-11 Thread Duncan Booth
Fuzzyman wrote:

> Tim Chase wrote:
> [snip]
>>   However, it's better to have a good relationship with your
>> customers and know that they will adhere to licensing conditions,
>> rather than to try and strong-arm them into behaving a particular
>> way.
>>
> 
> Don't forget that distributing your source code is more of a gift to
> your competitors (and potential competitors) than it is to your
> customers...
> 
I believe Eric Raymond has argued that if your competitors are spending 
their time trying to work out how to adapt to using your software, that is 
time they aren't spending competing with you. So long as you make regular 
releases of your software you can ensure that they are always at least one 
step behind you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Inconsistency producing constant for float "infinity"

2006-08-11 Thread Peter Hansen
I'm investigating a puzzling problem involving an attempt to generate a 
constant containing an (IEEE 754) "infinity" value.  (I understand that 
special float values are a "platform-dependent accident" etc...)

The issue appears possibly to point to a bug in the Python compiler, 
with it producing inconsistent results.  I'm using "Python 2.4.2 (#67, 
Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32".

This code sometimes produces a float of 1.0, sometimes infinity (or, 
since I'm on Windows, the float with string representation of "1.#INF"), 
as seen in the operand of the LOAD_CONST instruction:

def floatstr(o, allow_nan=True):
 INFINITY = 1e6

 # more code follows which does *not* rebind INFINITY


 >>> import dis
 >>> dis.dis(floatstr)
  27   0 LOAD_CONST   1 (1.0)
   3 STORE_FAST   2 (INFINITY)



And, at other times, under circumstances I've yet to isolate:

 >>> import dis
 >>> dis.dis(floatstr)
  27   0 LOAD_CONST   1 (1.#INF)
   3 STORE_FAST   2 (INFINITY)
 ...



I'll keep digging to narrow down what's going on, but I wondered if 
anyone had heard of or seen a similar problem, or is aware of an 
existing issue that could cause this.  I checked the list on sourceforge 
but can't see anything relevant, nor did Google help.

Just had a thought: could this be an issue involving "marshal" and 
either the writing of or reading of the .pyc file?  Is it known to be 
unsafe to have Python source with special float constants?

-Peter

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


Tab delimited file

2006-08-11 Thread Colin Wildsmith








Hello,

I am making a gui for the purpose that I can change the
values in a list of different criteria which is found in a text file, such as:

 

Name(tab)rating(tab)breast size(tab)occurrences

…

…

…

 

However as far as I know Python does not allow you to easily
change a specific line in a text file. You have to place the whole file to
memory, change what you need to and then write the file back after deleting the
previous information. 

 

Assuming this is true, how do i find where the tabs are in
the file so that I can distinguish between the different criteria? 

Assuming this is not true, does anyone suggest another way
to do it?

 

CoLe

 






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

Re: using an already running COM object with Dispatch

2006-08-11 Thread jiccab

Roger Upole wrote:
> "jiccab" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> > Greetings.
> >
> > with the following code,
> >
> > olApp = Dispatch("Outlook.Application")
> >
> > I am capable of getting a new instance of Outlook running.  I would
> > like to be able to use the instance that is already running, if exists,
> > otherwise open a new one.
> >
> > Has anyone being able to do this?
>
> You should be able to use
> win32com.client.GetActiveObject('outlook.application')
> and fall back to a normal Dispatch if it fails.
>
>  Roger

Yes indeed.  Thanks.  here is the code:

from win32com.client.dynamic import Dispatch
from win32com.client import GetActiveObject

def OutlookPointer():
  try:
olApp = GetActiveObject("Outlook.Application")
  except:
olApp = Dispatch("Outlook.Application")
  return olApp

op = OutlookPointer()

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


Re: some n00b question

2006-08-11 Thread Omar

John Salerno wrote:
> Omar wrote:
>
> > b) I'm also interested in created GUI's sooner rather than later.  Can
> > anyone point me to a fast track to doing GUI's on python?
>
> I recommend reading wxPython in Action. It's a great starter and
> reference to the wxPython GUI toolkit. Tkinter is usually considered
> easier and simpler, but I find it lacking in functionality, and wxPython
> is actually fairly easy to learn.

thanks, John

anyone on the music side?

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


Re: hide python code !

2006-08-11 Thread Paul Boddie
Ben Sizer wrote:
>
> It's worth remembering that there is a massive amount of software that
> has nothing to do with 'infrastructure', that won't need to be
> maintained, or upgraded. Examples include most retail software for the
> home or small office, and most entertainment software. Developers of
> such software often have understandable reasons for making it
> inconvenient to examine the algorithms at a high level.

It may be the case that certain kinds of applications can go on working
forever on whatever hardware they were intended to run, right until the
point when the hardware ceases to function correctly or when the
end-user gets bored of it, or envious of the neighbour's hardware, or
for whatever other reason. However, I've seen plenty of evidence of
"home or small office" software which arrives as a binary, employs its
own proprietary format, runs on now-legacy hardware and whose users are
now high-and-dry with respect to accessing their old documents.

Sure, developers of such software may not want their competitors to
find out how their products work - certain companies also like to file
patents for that added anticompetitive edge, should their competitors
even consider figuring out the not-so-magic formula - but as end-users
of software ourselves, we don't have to share such an understanding of
their motivations, especially when such motivations directly conflict
with our own: with respect to the above evidence, our own motivations
are to have a reasonable level of control over the tools to manage our
own data.

It may not matter if some console game or other doesn't work after 20
years, although I think it's actually something of a shame given that
such artifacts, no matter how apparently trivial they are, are actually
part of our culture and shouldn't be so readily discarded and
forgotten, but when your own data is not easily accessible within a
much shorter timeframe, the scandal is (at least to me) so much more
obvious.

Paul

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


Re: Tab delimited file

2006-08-11 Thread Tim Chase
> However as far as I know Python does not allow you to easily change a
> specific line in a text file. You have to place the whole file to memory,
> change what you need to and then write the file back after deleting the
> previous information. 
> 
> Assuming this is true, how do i find where the tabs are in the file so that
> I can distinguish between the different criteria? 


Well, I usually just use something like

NAME = 0
RATING = 1
SIZE = 2
OCCURS = 3
name = 'foo'
out = file('output.txt', 'w')
for line in file('input.txt'):
line = line.rstrip('\n')
items = line.split('\t')
# do something with items:
if name in items[NAME].lower():
items[RATING] = str(int(items[RATING]) + 1)
out.write('\t'.join(items))
out.write('\n')

which will loop through each line, incrementing the RATING field 
(assuming it's numeric?) where the NAME field contains 'foo'; 
then writing the resulting stuff back out to the output file.

-tkc



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


Re: Inconsistency producing constant for float "infinity"

2006-08-11 Thread Peter Hansen
Sybren Stuvel wrote:
> Peter Hansen enlightened us with:
> 
>>I'm investigating a puzzling problem involving an attempt to
>>generate a constant containing an (IEEE 754) "infinity" value.  (I
>>understand that special float values are a "platform-dependent
>>accident" etc...)
> 
> Why aren't you simply using the fpconst package?

Probably because it's not in the stdlib yet, assuming that's still true.

(Using it might be an option anyway.  I'm investigating a problem on 
Win32 with simplejson, so it would be Bob Ippolito's choice whether 
fpconst is a reasonable solution to the problem.)

My guess about marshal was correct.  The problem (value becoming 1.0) 
appears when running from .pyc files.  Immediately after the source code 
is changed, the code works, since it doesn't unmarshal the .pyc file but 
just works from the bytecode freshly compiled in memory.

This demonstrates what would be the heart of the problem, which I guess 
means this is not surprising to almost anyone, but perhaps will be a 
wakeup call to anyone who might still be unaware and has code that 
relies on constants like 1e producing infinities:

 >>> import marshal
 >>> marshal.dumps(1e666)
'f\x061.#INF'
 >>> marshal.loads(marshal.dumps(1e666))
1.0

-Peter

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


Re: Boost Install

2006-08-11 Thread missdeer



You should set PYTHON_ROOT & 
PYTHON_VERSION environment variable first, then set the VC toolset path, compile 
bjam.exe yourself and run bjam with -sTOOLS parameter.
It seems Boost has not been totally 
tested under VS2005, but works fine with VS2003.
Good luck!
 




missdeer
2006-08-11



发件人: 
Hoop
发送时间: 
2006-08-11 23:00:24
收件人: 
python-list@python.org
抄送: 
主题: Boost 
Install
 

Hi All,
I am wondering if any have done an install of Boost for Python
embedding?
I have downoaded boost_1_33_1.exe, ran that and now have a boost_1_33_1
directory with plenty of items ine it.
I have attempted to follow some online install directions which do not
seem to work. I am using VS2005.
I have tried, bjam "--with-python-version[=2.4] and just get a
statement saying that bjam is not recognized. Really is no batch file
or executable with that name in the boost directory.
Not sure what to do to get the Boost.Python installed.
Thanks for any help.
Jeff
 
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: some n00b question

2006-08-11 Thread Larry Bates
Omar wrote:
> I'm learning how to program python.  a few questions
> 
> a) I'm mostly interested in creating exe's that have to do with music
> -- things to help me keep track of chord progressions, transpositions,
> etc.  can anyone point me in the direction of resources on this?
> 
> b) I'm also interested in created GUI's sooner rather than later.  Can
> anyone point me to a fast track to doing GUI's on python?
> 
> thanks
> 
To create .exe's you will need to get py2exe:

http://www.py2exe.org/

I would add +1 to wxPython.  It takes a little while to get going,
IMHO it is the best Python GUI for Windows (it is also cross-
platform if that interests you).

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


Re: some n00b question

2006-08-11 Thread Gerard Flanagan
Omar wrote:
> I'm learning how to program python.  a few questions
>
> a) I'm mostly interested in creating exe's that have to do with music
> -- things to help me keep track of chord progressions, transpositions,
> etc.  can anyone point me in the direction of resources on this?
>
> b) I'm also interested in created GUI's sooner rather than later.  Can
> anyone point me to a fast track to doing GUI's on python?
>
> thanks

Hi Omar

are you aware of lilypond, used for typesetting music? (not what you
asked about I know!).  'lilycomp' is a simple (tkinter) gui for
creating lilypond markup, maybe some ideas there.

http://lilypond.org/web/

http://lilycomp.sourceforge.net/

hope that helps.

Gerard

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


Re: some n00b question

2006-08-11 Thread Omar

Gerard Flanagan wrote:
> Omar wrote:
> > I'm learning how to program python.  a few questions
> >
> > a) I'm mostly interested in creating exe's that have to do with music
> > -- things to help me keep track of chord progressions, transpositions,
> > etc.  can anyone point me in the direction of resources on this?
> >
> > b) I'm also interested in created GUI's sooner rather than later.  Can
> > anyone point me to a fast track to doing GUI's on python?
> >
> > thanks
>
> Hi Omar
>
> are you aware of lilypond, used for typesetting music? (not what you
> asked about I know!).  'lilycomp' is a simple (tkinter) gui for
> creating lilypond markup, maybe some ideas there.
>
> http://lilypond.org/web/
>
> http://lilycomp.sourceforge.net/
>
> hope that helps.
>
> Gerard

thank you Larry and thank you Gerard!  People on this forum are
apparantly quite cool.

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


Re: hide python code !

2006-08-11 Thread Ben Sizer
Paul Boddie wrote:
> Ben Sizer wrote:
> >
> > It's worth remembering that there is a massive amount of software that
> > has nothing to do with 'infrastructure', that won't need to be
> > maintained, or upgraded. Examples include most retail software for the
> > home or small office, and most entertainment software. Developers of
> > such software often have understandable reasons for making it
> > inconvenient to examine the algorithms at a high level.
>
> Sure, developers of such software may not want their competitors to
> find out how their products work - certain companies also like to file
> patents for that added anticompetitive edge, should their competitors
> even consider figuring out the not-so-magic formula - but as end-users
> of software ourselves, we don't have to share such an understanding of
> their motivations, especially when such motivations directly conflict
> with our own: with respect to the above evidence, our own motivations
> are to have a reasonable level of control over the tools to manage our
> own data.

I think you're possibly being a bit idealistic here. I use and endorse
open source and open formats wherever possible but I don't believe we
would have the same degree of diversity of software available if
everything was open.

Imagine if you were the single-person developer of a small application
that did something quite innovative, and charged a small fee for your
product. Now imagine you were practically forced to make your algorithm
obvious - a couple of months later, Microsoft bring out a freeware
version and destroy your business in an instant. Sure, they and others
can (and have) done that with closed-source products, but you increase
your chances of survival 10-fold if the key algorithms are not obvious.

The only other way to protect against that would be a software patent,
and I disagree with their existence on the grounds that it punishes
those who discover the techniques independently.

> It may not matter if some console game or other doesn't work after 20
> years...

Certainly; yet this is a valid example of software that requires a
degree of protection since some of the algorithms employed truly are
'worth stealing'. They can usually be replicated in time, but that may
be months and allows the original company to have a deserved commercial
advantage.

> ...although I think it's actually something of a shame given that
> such artifacts, no matter how apparently trivial they are, are actually
> part of our culture and shouldn't be so readily discarded and
> forgotten...

Thankfully we have emulators for most platforms, and hopefully
litigation won't kill those off.

> ...but when your own data is not easily accessible within a
> much shorter timeframe, the scandal is (at least to me) so much more
> obvious.

I think it's quite possible to have a closed binary but an open
document format, thus allowing the user to migrate away at any point
while still preserving any 'secrets' in the implementation.

-- 
Ben Sizer

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


Re: How to write a Installer for a Python App in Linux

2006-08-11 Thread diffuser78
I saw some examples and understood for most part how to write a
setpu.py.

Since I want to bundle python and wxPython along with my
application...how can I do that.

Any code gurus can throw some pointers.

Every help is appreciated.

Bruno Desthuilliers wrote:


> Look for distutil and EasyInstall (-> Python Eggs)

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


Automate logging into page

2006-08-11 Thread david brochu jr
I am trying to automate logging a website and have been unsuccessful. The code below is supposed to log me into the site, but changing the username/password to an incorrect combination does not cause an error or crash to be seen. My goal is to log into this page and save the cookie from the page so that when I spawn IE and navigate to this site I will be logged in. I am using the urllib2 module. Any suggestions? 
import urllibimport urllib2url = ''values = {'id_l_email': 'X', 'id_l_password':'X'}data = "">req = urllib2.Request(url,data)response = urllib2.urlopen(req)the_page = response.read()
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Read a file with open command

2006-08-11 Thread jean-jeanot
Sorry, but the access mode is not binary with XP Windows.  Finally for
reading the file it is necessary to use a slash or a double backslash.
If the file is a simple textfile, using a backslash is perhaps not
recommended but it is functionning.
Anyway many thanks.Here is the program:

>>> file_obj= open ("D:/Mes documents/ADB Anna.ods",'r')
>>> s = file_obj
>>> s.readlines()

Jean-Jeanot

Jan Svec a écrit :

> Hi,
> simply use file_obj = open ("D:\My documents\File.ods",'rb') for
> opening file in binary access mode, which is required for binary files
> on MS Windows.
> Honza
>
> jean-jeanot wrote:
> > I can access to a file with the command:
> > file_obj = open ( " D:\My documents\Textfile.txt",'r')
> >
> > When I now try to read a file with the following command:
> >
> > file_obj = open ("D:\My documents\File.ods",'r') it doesn't function.
> > The extension ods is coming from OpenOffice.org Calc.
> > 
> > Why ?
> > 
> > jean-jeanot

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


Re: using python to edit a word file?

2006-08-11 Thread Anthra Norell
No one could do it any better. Good for you! - Frederic

- Original Message -
From: "John Salerno" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To: 
Sent: Friday, August 11, 2006 4:08 PM
Subject: Re: using python to edit a word file?


> Anthra Norell wrote:
> > John,
> >
> >   I have a notion about translating stuff in a mess and could help you 
> > with the translation. But it may be that the
conversion
> > from DOC to formatted test is a bigger problem. Loading the files into Word 
> > and saving them in a different format may not be a
> > practical option if you have many file to do. Googling for batch converters 
> > DOC to RTF I couldn't find anything.
> >   If you can solve the conversion problem, pass me a sample file. I'll 
> > solve the translation problem for you.
> >
> > Frederic
>
> What I ended up doing was just saving the Word file as an XML file, and
> then writing a little script to process the text file. Then when it
> opens back in Word, all the formatting remains. The script isn't ideal,
> but it did the bulk of changing the numbers, and then I did a few things
> by hand. I love having Python for these chores! :)
>
>
>
> import re
>
> xml_file = open('calendar.xml')
> xml_data = xml_file.read()
> xml_file.close()
>
> pattern = re.compile(r'(\d+)')
>
> def subtract(match_obj):
>  date = int(match_obj.group(1)) - 1
>  return '%s' % date
>
> new_data = re.sub(pattern, subtract, xml_data)
>
> new_file = open('calendar2007.xml', 'w')
> new_file.write(new_data)
> new_file.close()
> --
> http://mail.python.org/mailman/listinfo/python-list

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


having issues Installing Python 2.5b3 on Windows XP

2006-08-11 Thread Bucco
I installed python 2.5b3 on my windows XP sp2 box without any issues.
I can double click the python program, and idle comes up in the command
line window.  However when I run python from the command line program
cmd.exe, I get a pop-up window with the following error:

16 bit Windows Subsystem
-

The NTVDM CPU has encountered an illegal instruction.
CS:020c IP:0115 OP:0f 00 00 00 00 Choose 'Close' to terminate the
application.


If I run python from the command line with the full path,
C:\Python25\python, no problem.  I checked my environment variables and
they are pointing to the correct directories.  I am at a loss for waht
is causing the issue.  Active state python 2.4 worked from the command
line with no issues.  I know 2.5b3 is beta, but I would like to try and
get it running properly.  At the very least, I would like someone to
report this bug so that the final version gets fixed.

Please don't say reboot.  I have already tried that, same problem.  I
am going to try to install python 2.4 with the msi installer and see if
I have the same issue with that version.  If anyone else has any ideas
please help.  

Thanks:)

SA

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


Re: Read a file with open command

2006-08-11 Thread Tim Williams
On 11 Aug 2006 09:39:23 -0700, jean-jeanot <[EMAIL PROTECTED]> wrote:

> Anyway many thanks.Here is the program:
>
> >>> file_obj= open ("D:/Mes documents/ADB Anna.ods",'r')
> >>> s = file_obj
> >>> s.readlines()

Please remember not to top-post :)

Try this

>>> s = open ("D:/Mes documents/ADB Anna.ods",'r')
>>> s.readlines()
>>> s.close()

or

>>> s = open ("D:/Mes documents/ADB Anna.ods",'r').readlines()

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


Re: Tkinter module not found

2006-08-11 Thread Philippe Martin
Shuaib wrote:

> Hey,
> 
> Even though I freshly installed Tcl and Tk, python still seem to have
> problems accessing Tkinter module. Here is what says when I do "import
> Tkinter"
> 
> ==
> Traceback (most recent call last):
>   File "", line 1, in ?
> ImportError: No module named Tkinter
> ==
> 
> Any ideas how to fix this problem? (Gentoo distribution)
> 
> Thanks.
That happened once to me when I compiled python without tcl/tk installed
(prior to compiling)


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


Re: PIL Image transform

2006-08-11 Thread Ben C
On 2006-08-09, Dean Card <[EMAIL PROTECTED]> wrote:
> Okay, so here is the situation.  I have need to do some on-the-fly image 
> creation.  I have everything working great except for the last part of it, 
> applying a perspective type transform to the image.  The transform will take 
> a rectangular 2D image and transform it to a 3D representation in 2D.
>
> Please see the link to see what I am trying to do:
> http://seanberry.com/transform.png
>
> I have PIL v1.15 installed which has a PERSPECTIVE transform, but it does 
> not appear to do what I want - or I can't figure out how to use it correctly 
> because it is using a transform matrix's coefficients.
>
> Here is the only info I could find on the usage:
> http://mail.python.org/pipermail/image-sig/2005-February/003198.html

This looks like a correct description of the sources:

In Image.py:

elif method == PERSPECTIVE:
# change argument order to match implementation
data = (data[2], data[0], data[1],
data[5], data[3],
data[4],
data[6],
data[7])

and then in Geometry.c:

static int
perspective_transform(double* xin, double* yin, int x, int y, void*
data)
{
double* a = (double*) data;
double a0 = a[0]; double a1 = a[1]; double a2 = a[2];
double a3 = a[3]; double a4 = a[4]; double a5 = a[5];
double a6 = a[6]; double a7 = a[7];

xin[0] = (a0 + a1*x + a2*y) / (a6*x + a7*y + 1);
yin[0] = (a3 + a4*x + a5*y) / (a6*x + a7*y + 1);

return 1;
}

> This is for the creation of images to be used in Flash.  Originally I was 
> doing the image processing in Flash because Flash 8 has a BitmapData class 
> which does the basics of images, copy, transform, etc.  To accomplish the 
> transform I was using an algorithm that approximated triangles to fill and 
> worked really well, but I need the image processing to be server side, not 
> client.
>
> So, here I am.  Anyone have any idea how to accomplish my goal here?  Is 
> there a way to fill a triangle with a bitmap using PIL?  What about better 
> docs on the PERSPECTIVE transform?
>
> Thanks for any and all help on this.

Something like this is almost what you what:

im = im.transform(im.size, Image.PERSPECTIVE, (1, 0, 0, 0, 1, 0, -0.004, 0))

But the problem really is that the top row of the image is at at y of
0-- I think you want the origin of the image to be in the centre for
this to work properly.

Is there a way to do that in PIL?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read a file with open command

2006-08-11 Thread jean-jeanot
Dear Sybrel,

I am delighted to know that you have been enlighted through my
question.
I am aware of my stupidity and I would say of my ignorance.If all
Python users were not ignorant I suppose  the Python group would be
superfluous. I would suggest that if if you think that a question is
supid please do not answer it.In French we say: "There is no stupid
question but answers can be stupid". For the citation of Zappa I am
convinced that when Zappa is speaking of world stupidity he is thinking
to stupidity and wickedness of mankind and not to ignorance.
Anyway the open command with a file having the extension ods must be
used with a slash. But with a double backslash it is functionning too.
In every documentation I posess on Python it is mentioned that an
absolute path in Windows starts with a backslash.Python accepts
platform-specific syntax ( See Python by C. Fehilly , p 306, Python in
a nutshell by Martelli, etc,etc)
Anyway thank you for your answer.

jean-Jeanot

Sybren Stuvel a écrit :

> jean-jeanot enlightened us with:
> > I can access to a file with the command:
> > file_obj = open ( " D:\My documents\Textfile.txt",'r')
>
> Which is the wrong way. Use forward slashes, escape your backslashes,
> or use raw strings.
>
> 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: How to write a Installer for a Python App in Linux

2006-08-11 Thread diffuser78
Hi,

How can we freeze the python program and how will it ensure that all
the python files are packages with the programs (including python and
wxPython). Can anybody give me some pointers on this.

Every help is appreciated. Thanks.

> You could freeze the Python program. That'll ensure all the required
> files are packaged with your program, including Python itself. If you
> build a RPM from that, your users will be quite happy.
 
> Sybren

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


Including python and wxPython in distutils

2006-08-11 Thread diffuser78
I wrote a small app in python and used wxPython in it. Now, I am trying
to create an .rpm file for linux RedHat Distro. I want the ability in
my installer to install python2.4 and wxPython too along with the .py
files which are in the project.

I am trying to use distutils. Can anybody give some pointers to do this
fast ?

Every help is greatly appreciated.

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


Re: What's the cleanest way to compare 2 dictionary?

2006-08-11 Thread John Henry

John Machin wrote:
> John Henry wrote:
> > John,
> >
> > Yes, there are several scenerios.
> >
> > a) Comparing keys only.
> >
> > That's been answered (although I haven't gotten it to work under 2.3
> > yet)
>
> (1) What's the problem with getting it to work under 2.3?
> (2) Why not upgrade?
>

Let me comment on this part first, I am still chewing other parts of
your message.

When I do it under 2.3, I get:

common_eq = set(k for k in _common if a[k] == b[k])
   ^
SyntaxError: invalid syntax

Don't know why that is.

I can't  upgrade yet.  Some part of my code doesn't compile under 2.4
and I haven't got a chance to investigate further.

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


  1   2   >